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.

1
  • there is also a more complete answer here : serverfault.com/questions/241588/… , unfortunatly I didn't see it before posting, neither do I notice U&L's answer. Commented Feb 26, 2015 at 8:11

2 Answers 2

3

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

sshpass -p 'password' ssh 192.168.1.1
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).

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.