6

I can ssh from my pc using putty, 1 line like so ssh root@myname.mydomain.us -pw abc123
but when I try this from OSX terminal, I get an error Bad port 'w'

How can make this work on OSX?

19

ssh does not support passing a password on the command line, it is interpreting the -pw as "Connect to port w".

In order to do automated logins via ssh, use .ssh/authorized_keys:

  • On the OSX terminal, create a key using ssh_keygen. If you accept the default filenames, your ssh client will automatically try this key when it connects.
  • Copy the contents of the resultant .pub file and add it to .ssh/authorized_keys on the destination host (eg myname.mydomain.us:~root/.ssh/authorized_keys)

If your heart is set on passwords via the commandline, the expect toolset can be used to interact with STDIN/STDOUT on running commands.

11

What you're trying to do is impossible with the built-in SSH client in OS X. The OpenSSH client is incapable of accepting a password from the command line.

The reason you're getting the "Bad port" error is because the -p flag is used to specify the port to connect to and the -pw flag does not exist. See the man page for more details.

Additionally, it's almost always a bad idea to specify a password from the command line. Have you looked into using public key authentication?

1
  • I'm trying to tell my mom over the phone how to SSH to my computer so I can help her with stuff remotely. She can copy an SSH command, but the blind password entry confuses her, and there's zero chance I'm walking her through setting up public key auth. Besides, there are other weird reasons to need to send the password in one line; why can't SSH just let me use it the way I want?
    – sudo
    Mar 26 at 20:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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