如何实现非交互式远程登录Linux系统

一般ssh远程linux系统时,需要交互式的输入远程系统的登录密码,形式如下:

在脚本中进行批量登录的时候,极为不方便。如何能实现非交互式登录,网上看到实现方式,大概有三种方法:

1. ssh时,明确远程系统的pwd

    这种方法,First you need to install sshpass.

    Example: sshpass -p "YOUR_PASSWORD" ssh -o StrictHostKeyChecking=no YOUR_USERNAME@SOME_SITE.

    Refer to: http://stackoverflow.com/questions/12202587/automatically-enter-ssh-password-with-script

2. 利用public key authenticaiton

     You can login to a remote Linux server without entering password in 3 simple steps using ssky-keygen and ssh-copy-id as explained.

     ssh-keygen creates the public and private keys. ssh-copy-id copies the local-host’s public key to the remote-host’s authorized_keys file. ssh-copy-id also assigns proper permission to the remote-host’s home, ~/.ssh, and ~/.ssh/authorized_keys.

    

    

    

    

       Refer to:

       http://www.thegeekstuff.com/2008/11/3-steps-to-perform-ssh-login-without-password-using-ssh-keygen-ssh-copy-id/

       https://www.digitalocean.com/community/tutorials/how-to-use-ssh-to-connect-to-a-remote-server-in-ubuntu

3. 利用expect编程实现

 

posted @ 2014-06-26 13:49  IT麦兜  阅读(1046)  评论(0)    收藏  举报