You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.8 KiB
50 lines
1.8 KiB
defHostfile=/home/jumpserver/.hostfile
|
|
defPort=22
|
|
defRSA=/home/jumpserver/.ssh/id_rsa.pub
|
|
|
|
stty erase ^H
|
|
# 禁止用户使用ctrl+c 等操作
|
|
warn(){
|
|
echo "禁止的操作"
|
|
}
|
|
|
|
addHost(){
|
|
if [ ! -f $defHostfile ];then
|
|
touch $defHostfile
|
|
fi
|
|
_id=$[$(cat $defHostfile |wc -l) + 1]
|
|
read -p "请输入服务器地址:" rhost
|
|
read -p "请输入服务器用户:" ruser
|
|
read -p "请输入服务器端口:" rport
|
|
read -s -p "请输入服务器密码:" rpasswd
|
|
echo ""
|
|
read -p "请输入服务器用途:" rdesc
|
|
sshpass -p "$rpasswd" ssh-copy-id -o StrictHostKeyChecking=no -i $defRSA -p $defPort ${ruser}@${rhost} &>/dev/null || echo "添加服务器异常,请检查密码或联系管理员" && \
|
|
printf "%5s] %-20s %-10s %-5s %-30s\n" "$_id" "$rhost" "$ruser" "$rport" "$rdesc" >> $defHostfile &&\
|
|
echo -e "$rhost 服务器添加成功\n用户:$ruser\n密码:$rpasswd\n注意,密码仅展示一次!"
|
|
}
|
|
|
|
connHost(){
|
|
printf "%-5s %-20s %-10s %-5s %-30s\n" "id" "host" "user" "port" "desc"
|
|
while read line
|
|
do
|
|
id=$(echo $line | awk '{print $1}')
|
|
host=$(echo $line | awk '{print $2}')
|
|
user=$(echo $line | awk '{print $3}')
|
|
port=$(echo $line | awk '{print $4}')
|
|
desc=$(echo $line | awk '{print $5}')
|
|
printf "%-5s %-20s %-10s %-5s %-30s\n" "$id" "$host" "$user" "$port" "$desc"
|
|
done<$defHostfile
|
|
read -p "请输入服务器编号:" num
|
|
num=${num:+$num]}
|
|
host=$(grep "$num" $defHostfile)
|
|
if [ ! -z "$host" ];then
|
|
_host=$(echo $host | awk '{print $2}')
|
|
_user=$(echo $host | awk '{print $3}')
|
|
_port=$(echo $host | awk '{print $4}')
|
|
echo "正在连接服务器 ${_user}@${_host}:${_port} ..."
|
|
ssh -o StrictHostKeyChecking=no ${_user}@${_host} -p ${_port}
|
|
else
|
|
echo "服务器不存在"
|
|
fi
|
|
} |