The situation:

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

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

  • 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.


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

sshpass -p 'password' ssh

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";

(Or sshpass as the other commentator has mentioned).

Not the answer you're looking for? Browse other questions tagged or ask your own question.