Server B ---ssh---> Server A ,without password
(1)@ServerB
shell> ssh-keygen -t dsa
(Just Enter,Enter,Enter)
there were 2 files (id_dsa, id_dsa.pub) at ~/.ssh
shell> scp ~/.ssh/id_dsa.pub [@serverA]:~/.ssh/B_dsa.pub
(2)@ServerA
shell> cd ~/.ssh
shell> cat B_dsa.pub >> ~/.ssh/authorized_keys
(3)@ServerB
shell> ssh serverA
[Supplementary]
##1. ssh without interaction and passphrase ,add by sean in 2012/11/27
##1-1. Generate a key in ssh client , with temporary key '123456'. file name as hostname
[root@client ~]# ssh-keygen -t dsa -N "123456" -f ~/.ssh/$(hostname)
##1-2. Remove passphrase inside private key(~/.ssh/id_dsa), ~/.ssh/id_dsa should be with permission 600
[root@client ~]# openssl dsa -in ~/.ssh/$(hostname) -out ~/.ssh/id_dsa -passin pass:123456
[root@client ~]# chmod 600 ~/.ssh/id_dsa
##1-3. copy public key to the server [192.168.122.11]
[root@client ~]# scp ~/.ssh/$(hostname).pub 192.168.122.11:~/.ssh/.
[root@client ~]# rsync -av /root/.ssh/$(hostname).pub 192.168.122.11:/root/.ssh/$(hostname).pub
##1-4. merge all client's public-key into ~/.ssh/authorized_keys
[root@client ~]# cd ~/.ssh
[root@client ~]# cd ~/.ssh
[root@client ~]# cp client1.pub client2.pub ... authorized_keys
##2. no message prompt when a new-host ssh connection had been built ,add by sean in 2012/11/27
##2-1. command-line option connect to server(192.168.122.11)
##2-1. command-line option connect to server(192.168.122.11)
[root@client ~]# ssh -o StrictHostKeyChecking=no' -o 'BatchMode=yes' 192.168.122.11
### StrictHostKeyChecking=no : add host key directly(no ask) into ~/.ssh/know_hosts
### StrictHostKeyChecking=no : add host key directly(no ask) into ~/.ssh/know_hosts
### BatchMode=yes : no interactive when connecting to server
##2-2. config in client ( when you modifed the config , you don't need to connect to serve with options (-o)
[root@client ~]# vi /etc/ssh/ssh_config
:
:
StrictHostKeyChecking=no
BatchMode=yes
[root@client ~]# vi /etc/ssh/ssh_config
:
:
StrictHostKeyChecking=no
BatchMode=yes
##3. administration when host changed (changed ip , OS re-install...) ,add by sean in 2012/11/27
##3-1. remove client's(192.168.122.15) old key
[root@server ~]# ssh-keygen -R 192.168.122.15
##3-1. remove client's(192.168.122.15) old key
[root@server ~]# ssh-keygen -R 192.168.122.15
##3-2. scan client's new key and append into ~/.ssh/known_hosts
[root@server ~]# ssh-keyscan 192.168.122.15 | tee -a ~/.ssh/known_hosts
[root@server ~]# ssh-keyscan 192.168.122.15 | tee -a ~/.ssh/known_hosts
##3-3. scan server's key and append into ~/.ssh/known_hosts
[root@client ~]# ssh-keyscan 192.168.122.11 | tee -a ~/.ssh/known_hosts
[root@client ~]# ssh-keyscan 192.168.122.11 | tee -a ~/.ssh/known_hosts
沒有留言:
張貼留言