這個腳本須要仔細看看,實用價值不錯,無密鑰鏈接詳情能夠看(本博文S02)bash
執行的腳本的過程:app
[root@cnsz142728 profile.d]# su - jump [jump@cnsz142728 ~]$ ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa (生成密鑰公鑰) Generating public/private dsa key pair. Your identification has been saved in /home/jump/.ssh/id_dsa. Your public key has been saved in /home/jump/.ssh/id_dsa.pub. The key fingerprint is: 77:57:90:82:75:9b:7e:54:d5:e7:bc:15:86:de:b0:fe jump@cnsz142728 The key's randomart image is: +--[ DSA 1024]----+ | o. +.=| | . .+.*+| | ..Bo=| | + ++| | S . o o +| | . . o o | | . | | E | | | +-----------------+ [jump@cnsz142728 ~]$ ssh-copy-id -i ~/.ssh/id_dsa.pub 10.25.172.91 The authenticity of host '10.25.172.91 (10.25.172.91)' can't be established. RSA key fingerprint is 69:0c:9e:d9:dd:68:08:35:3b:1f:c4:40:c7:a9:7f:40. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '10.25.172.91' (RSA) to the list of known hosts. jump@10.25.172.91's password: Now try logging into the machine, with "ssh '10.25.172.91'", and check in: .ssh/authorized_keys to make sure we haven't added extra keys that you weren't expecting. [jump@cnsz142728 ~]$ ssh-copy-id -i ~/.ssh/id_dsa.pub 10.25.172.90 jump@10.25.172.90's password: Now try logging into the machine, with "ssh '10.25.172.90'", and check in: .ssh/authorized_keys to make sure we haven't added extra keys that you weren't expecting.
[root@cnsz142728 profile.d]#echo '[ $UID -ne 0 ] && . /server/scripts/jump.sh'>/etc/profile.d/jump.sh [root@cnsz142728 profile.d]# cat jump.sh [ $UID -ne 0 ] && . /server/scripts/jump.sh
[root@cnsz142728 scripts]# cat jump.sh #!/bin/bash ##by Carlton at 10171018,I am study by oldboy trapper(){ trap ':' INT EXIT TSTP TERM HUP } main(){ while : do trapper clear cat <<menu 1)machine01-10.25.172.90 2)machine02-10.25.172.91 menu read -p "Pls input a num :" num case "$num" in 1) echo "login in 10.25.172.90" ssh 10.25.172.90 ;; 2) echo "login in 10.25.172.91" ssh 10.25.172.91 ;; 110)read -p "your birthday:" char if [ "$char" = "0819" ];then exit sleep 5 fi ;; *) echo "select error." exit esac done } main
[root@cnsz142728 scripts]# su jump 1)machine01-10.25.172.90 2)machine02-10.25.172.91 Pls input a num :1 login in 10.25.172.90 WARNING: If you are not authorized to access this private computer system, disconnect now. All activities on this system will be monitored and recorded without prior notification or permission! [jump@cnsz142726 ~]$ logout Connection to 10.25.172.90 closed. 1)machine01-10.25.172.90 2)machine02-10.25.172.91 Pls input a num :2 login in 10.25.172.91 WARNING: If you are not authorized to access this private computer system, disconnect now. All activities on this system will be monitored and recorded without prior notification or permission! [jump@cnsz142727 ~]$ logout Connection to 10.25.172.91 closed. 1)machine01-10.25.172.90 2)machine02-10.25.172.91 Pls input a num :3 select error. [root@cnsz142728 scripts]# su jump 1)machine01-10.25.172.90 2)machine02-10.25.172.91 Pls input a num :110 your birthday:0819 [root@cnsz142728 scripts]#
你們能夠結合執行的結果進行腳本的理解,也能夠運用到本身的生產機器當中,機器數量也能夠增長!dom