3

The situation:

  • I have an IP : 192.168.1.1 $IP
  • username : root (or whatever) $USER
  • and a passwd: foo $PASSWD

Is there a way to give $PASSWD to ssh ? like

 PASSWORD_VAR=$PASSWD ssh -l $USER $IP
  • user can see the password,
  • user must "land" on usual interactive shell session.
  • somme package might be installed on desktop linux if need be.

reading ssh(1) give me no clues. such thing exists in window's world (e.g. Kitty), now I would like to do the same in unix (suse or unbuntu if that matter).

I know how to set up public/private key pair, but this is off topic.

Archemar
  • 31,554
  • there is also a more complete answer here : http://serverfault.com/questions/241588/how-to-automate-ssh-login-with-password , unfortunatly I didn't see it before posting, neither do I notice U&L's answer. – Archemar Feb 26 '15 at 08:11

2 Answers2

3

It is possible if you can install sshpass, so you can run:

sshpass -p 'password' ssh 192.168.1.1
taliezin
  • 9,275
2

ssh by default and by design doesn't do it. This is because clear text passwords embedded in scripts is pretty fundamentally a bad idea. Not least because - if it's specified on a single command line, it normally shows up in the ps list that every user can see. So it's deliberately made difficult, to encourage better habits. public-private key pairs and ssh-agent go a long way to removing the requirement.

If you've really a need, then expect can do it:

#!/usr/bin/expect -f

spawn /usr/bin/ssh -n username@hostname 
expect "password:"
send "Password\n";
interact

(Or sshpass as the other commentator has mentioned).

Sobrique
  • 4,424