2015年11月15日 星期日

[Linux 常見問題] Connect through SSH and type in password automatically, without using a public key

Source From Here 
Question 
A server allows SSH connections, but not using public key authentication. It's not within my power to change this at the moment (due to technical difficulties, not organizational) but I will get on it as soon as possible! What I need now is to execute commands on the server using plain old account+password authentication from a script. That is, I need to do it in a non-interactive way. Is it possible? And how do I do it? 

How-To 
There is a linux utility called sshpass. It allows you to do exactly what you want and will take a server password either as a command line argument, or from a file (i prefer this way, so i do not have my server password show up in shell history) and you use it like so: 
# sshpass -f file_with_password ssh user@server ls -la
Or
# sshpass -p 'your_password' ssh user@server ls -la

This will ssh into a server and run ls -laOne thing, however, you have to manually ssh into a server first (if you haven't done so already), so the server gets added to your ~/.ssh/known_hosts. If you don't do that, sshpass will not work. 

Supplement 
nixCraft - sshpass: Login To SSH Server / Provide ... Password Using A Shell Script 
[Linux 文章收集] sshpass Command : Non-interactive Password Authentication with SSH

沒有留言:

張貼留言

[Git 常見問題] error: The following untracked working tree files would be overwritten by merge

  Source From  Here 方案1: // x -----删除忽略文件已经对 git 来说不识别的文件 // d -----删除未被添加到 git 的路径中的文件 // f -----强制运行 #   git clean -d -fx 方案2: 今天在服务器上  gi...