1

I want to login using ssh and password store in a text file or may be in a varible

I am trying below method but i am getting an error please suggest me correct way.

echo "123456" | ssh root@127.0.0.1

error: Pseudo-terminal will not be allocated because stdin is not a terminal.

enter image description here

Tiger
  • 666

2 Answers2

2

Ideally, you would want to use ssh keys instead of a plaintext password stored in a file/script. This looks like a duplicate of https://stackoverflow.com/questions/4594698/using-a-variables-value-as-password-for-scp-ssh-etc-instead-of-prompting-for

Jason Rush
  • 1,908
  • 1
  • 12
  • 12
1

Install sshpass with below commands.

wget http://dl.fedoraproject.org/pub/epel/6/x86_64/sshpass-1.05-1.el6.x86_64.rpm

 rpm -ivh sshpass-1.05-1.el6.x86_64.rpm

Now login with ssh

sshpass -p ‘password’ ssh root@IP

  • 2
    a little bit more secure is to use: SSHPASS=123456 sshpass -e ssh root@127.0.0.1 this will hide the password using ps... – LilloX Dec 16 '15 at 08:13