1:通过ssh公钥进行秘钥认证,将本机与远程主机建立信任关系。
2:通过expect
#!/usr/bin/expect -f
spawn scp test.sh username@host:/home/username/
expect "*Password"
send "password\r"
expect eof
3:通过sshpass
密码保存在文件第一行:sshpass -fpassfile ssh -o StrictHostKeyChecking=no username@host.
脚本输入密码:sshpass -ppassword ssh -o StrictHostKeyChecking=no username@host
密码设置在环境变量:sshpass -e ssh -o StrictHostKeyChecking=no username@host
4:对于需要root权限执行的脚本,可以在/etc/sudoers中将对应的用户设置为
username ALL=(ALL) NOPASSWD:ALL
5:ssh -t username@machine command.可以与远程交互