ssh keyless login



Three centos, one server, 192.168.2.152, one client, 192.168.2.142, one client, 192.168.2.151

(1) Generate keyless

 [root@localhost ~]# ssh-keygen -t dsa

Generating public/private dsa key pair .

Enter file in which to save the key (/root/.ssh/id_dsa):

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /root/.ssh/id_dsa.

Your public key has been saved in /root/.ssh/id_dsa.pub.

The key fingerprint is:

fa:65:a6:b8:6f:d1:f1:e0:40:2e:56:50:85:24:99:b5 [email protected]

The key's randomart image is:

+--[ DSA 1024]----+

| oB+o. |

| o.+. |

| +E |

| ooo |

| . .S + + |

| .. o . | |

. .+ |

| o.= |

| Press Enter (2) to view the generated key. Two files will be generated. One id_dsa is the key and one id_dsa.pub is the public key [root@localhost ~]# ls -l .ssh/ total usage 12 -rw---- ---. 1 root root 616 Mar 28 23:12 authorized_keys -rw-------. 1 root root 672 Mar 29 02:35 id_dsa -rw-r--r--. 1 root root 616 March 29 02:35 id_dsa.pub (3) To send the public key to other servers, enter yes and the password of the opposite server. Pay special attention here if the other party's ssh port is not 22, but other ports are enclosed in "" and -p for example ssh-copy-id -i .ssh/id_dsa.pub "-p21 [email protected]" [root@localhost ~]# ssh-copy-id -i .ssh/id_dsa.pub [email protected] The authenticity of host '192.168.2.142 (192.168.2.142)' can't be established.































RSA key fingerprint is 1c:f0:dd:01:d6:58:5e:e9:07:37:b4:cc:c4:91:59:de.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added '192.168.2.142' (RSA) to the list of known hosts.

[email protected]'s password:

Now try logging into the machine, with "ssh '[email protected]'", and check in:




  .ssh/authorized_keys




to make sure we haven't added extra keys that you weren't expecting.

(4)无密钥登录

[root@localhost ~]# ssh -p22 [email protected]

Last login: Sun May  6 20:15:39 2018 from 192.168.2.149

[root@localhost ~]# ip a | grep 192.168

    inet 192.168.2.142/24 brd 192.168.2.255 scope global dynamic ens33

    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0

(5) Transfer files to the client server 142 scp -p22 port -rp r is the directory p is not changed the file attribute bao directory name root user @ip : /root storage path

[root@localhost ~]# scp -p22 -rp bao/ [email protected]:/root

apache-tomcat-9.0.5.tar.gz 100% 9254KB 9.0MB/s 00:00    

grafana-3.1.1-1470047149.x86_64.rpm 100% 39MB 38.7MB/s 00 :01    

sunlogin_remoteclient_2.2.0.39537Beta.tar.gz 100% 2849KB 2.8MB/s 00:00    

zabbix-3.4.7.tar.gz 100% 16MB 16.4MB/s 00:00    

nginx-1.13.9.tar.gz 100 % 971KB 971.5KB/s 00:00    

jdk-8u162-linux-x64.tar.gz 100% 181MB 45.3MB/s 00:04   

Client view

[root@localhost ~]# cd bao/

[root@localhost bao]# ls

apache-tomcat-9.0.5.tar.gz nginx-1.13.9.tar.gz

grafana-3.1.1-1470047149.x86_64.rpm sunlogin_remoteclient_2.2.0.39537Beta.tar.gz

jdk-8u162-linux-x64.tar. gz zabbix-3.4.7.tar.gz

(6) Write the script

to the 192.168.2.151 service and pass in the public key

vi ssh.sh

The first method

scp -p22 -rp bao/ [email protected]:/root

scp -p22 -rp bao/ [email protected]:/root

The second method

for n in 142 151

do

scp -p22 -rp bao/ [email protected].$n:/root

done




sh ssh.sh

[root@ localhost ~]# sh ssh.sh

apache-tomcat-9.0.5.tar.gz 100% 9254KB 9.0MB/s 00:00    

grafana-3.1.1-1470047149.x86_64.rpm                                                                100%   39MB  38.7MB/s   00:00    

sunlogin_remoteclient_2.2.0.39537Beta.tar.gz                                                       100% 2849KB   2.8MB/s   00:00    

zabbix-3.4.7.tar.gz                                                                                100%   16MB  16.4MB/s   00:00    

nginx-1.13.9.tar.gz                                                                                100%  971KB 971.5KB/s   00:00    

jdk-8u162-linux-x64.tar.gz                                                                         100%  181MB  90.5MB/s   00:02    

apache-tomcat-9.0.5.tar.gz                                                                         100% 9254KB   9.0MB/s   00:00    

grafana-3.1.1-1470047149.x86_64.rpm                                                                100%   39MB  38.7MB/s   00:01    

sunlogin_remoteclient_2.2.0.39537Beta.tar.gz                                                       100% 2849KB   2.8MB/s   00:00    

zabbix-3.4.7.tar.gz                                                                                100%   16MB  16.4MB/s   00:00    

nginx-1.13.9.tar.gz                                                                                100%  971KB 971.5KB/s   00:00    

jdk-8u162-linux-x64.tar.gz                                                                         100%  181MB  60.3MB/s   00:03    







Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325561247&siteId=291194637