如何实现非交互式远程登录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:
3. 利用expect编程实现

浙公网安备 33010602011771号