SSH in shell script with password

2020-02-15 08:36发布

I want to write one shell script like

command1    
ssh vivek@remotehost 
    fire command on remote host

Now I have password in pass.txt . But when I change stdin with file. It is not reading password from file.

script.sh < password.txt 

It is prompting for the password in place of reading password from the file. What I am doing wrong ?

Second problem is that shell script don't shows the command fired. Is there a way , I can show fired command from it ?

Note : I don't have key based access on remote system. I can only use password based login for ssh.

标签: shell ssh
3条回答
聊天终结者
2楼-- · 2020-02-15 09:01

OpenSSH ssh does not reads the password from stdin but from /dev/tty. That's why you have to use Expect or some other similar tool to automate it.

plink is another client, also available for Linux/Unix that accepts the password as a parameter on the command line... though that has some ugly security implications.

查看更多
Ridiculous、
3楼-- · 2020-02-15 09:06

You can use ssh-agent or expect (the programing language) to do this.

查看更多
男人必须洒脱
4楼-- · 2020-02-15 09:09

Okay, just to mention yet another option: sshpass is a tool developed for exactly the task of "fooling" regular openssh client to accept password non-interactively.

查看更多
登录 后发表回答