zoukankan      html  css  js  c++  java
  • ssh 无秘钥登录



    三台centos 一台服务器192.168.2.152 一台客户端192.168.2.142 一台客户端192.168.2.151

    (1)产生无密钥

     [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 root@localhost.localdomain

    The key's randomart image is:

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

    |      oB+o.      |

    |      o.+.       |

    |       +E        |

    |      o o o      |

    |     . .S+ +     |

    |       .. o .    |

    |      .  .+      |

    |       o.=       |

    |      o++        |

    +-----------------+




    注意这里要默认敲三下回车




    (2)查看产生的密钥   会产生两个文件一个id_dsa是密钥 一个id_dsa.pub是公钥

    [root@localhost ~]# ls -l .ssh/

    总用量 12

    -rw-------. 1 root root 616 3月  28 23:12 authorized_keys

    -rw-------. 1 root root 672 3月  29 02:35 id_dsa

    -rw-r--r--. 1 root root 616 3月  29 02:35 id_dsa.pub

    (3)把公钥发给其他服务器 要输入yes 和对向服务器的密码   这里特别注意如果对方ssh端口不是22,是其他端口用""括起来加-p

    例如ssh-copy-id -i .ssh/id_dsa.pub "-p21  root@192.168.2.142"

    [root@localhost ~]# ssh-copy-id -i .ssh/id_dsa.pub root@192.168.2.142

    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.

    root@192.168.2.142's password:

    Now try logging into the machine, with "ssh 'root@192.168.2.142'", 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 root@192.168.2.142

    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)传文件给客户端服务器 142   scp -p22端口 -rp r是目录 p是不改变文件属性 bao目录名字 root用户@ip : /root 存放的路径

    [root@localhost ~]#  scp -p22 -rp bao/ root@192.168.2.142:/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   

    客户端查看

    [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)写到脚本里

    给192.168.2.151服务传入公钥

    vi ssh.sh

    第一种方法

    scp -p22 -rp bao/ root@192.168.2.142:/root

    scp -p22 -rp bao/ root@192.168.2.151:/root

    第二种方法

    for n in 142 151

    do

    scp -p22 -rp bao/ root@192.168.2.$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    







  • 相关阅读:
    【SCOI 2011】 糖果
    【POJ 3159】 Candies
    【POJ 1716】 Integer Intervals
    【POJ 2983】 Is the information reliable?
    【POJ 1364】 King
    【POJ 1201】 Intervals
    【POJ 1804】 Brainman
    6月10日省中提高组题解
    【POJ 3352】 Road Construction
    【POJ 1144】 Network
  • 原文地址:https://www.cnblogs.com/houchaoying/p/9002003.html
Copyright © 2011-2022 走看看