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

標籤

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

沒有留言:

張貼留言

網誌存檔

關於我自己

我的相片
Where there is a will, there is a way!