1

So my .command file looks like this

ssh someuser@someip.com

When I run just this it prompts me for the password, how do I make terminal enter the password instead of me having to type it in? I have tried this:

ssh someuser@someip.com
password

But that does not work.

1

You could store ssh keys or store your password in the ~/.ssh/config file (see man ssh_config for details) but that would be kind of cheating since it's not really in your .command file.

You could of course script the addition (and optionally removal) of the entries needed to modify ssh keys or config file changes.

I would make a simple expect script - to wait for the password prompt and then enter your password.

#!/usr/bin/expect -f
set bad_idea cleartext_passwords_are_insecure
set timeout -1
# now connect using ssh
spawn ssh user@example.com
expect "*?assword:*"
send -- "$bad_idea\r"
send -- "\r"
expect elf

You don't have use a $bad_idea variable and could just send the password before the \r

  • 1
    ssh keys are definitely the way to go. They have numerous advantages. You can change the password on them without distributing a new public key. Keychain remembers the password if you want it. Once you load the key in memory it's remembered so you don't need to enter it again. All of this is controllable so you can adjust the security/convenience balance. Definitely ssh keys! – jsd Mar 12 '14 at 23:22
  • @jsd I want to find another question so that you can answer how to do this with ssh keys. It is really the best possible way to accomplish the larger goal IMO. – bmike Mar 13 '14 at 1:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .