I'm figuring out how to best create a bash script that accepts username, password and host as input and can then use ssh/rsync/scp to connect. It seems that these programs only accept password that is given by the user via prompt.
Note: I am well familiar with SSH keys - my use case is a situation where one wants to programmatically place an SSH key to a server where a key does not exist.
My current solution is to use expect
to answer the password prompt with the correct password (and provide all other information as parameters).
如果您不介意密码对其他用户可见,则可以按照此答案中的建议使用sshpass
:
sshpass -p<password> ssh <arguments>
The best solution for jobs like these (connecting anything over SSH, be it ssh itself, scp or rsync) is to use keys for authentification.
Then you can add your key to the auth manager (or just leave it without passphrase, but then be careful!) and use it to connect to the host.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.