I can SSH from my pc using putty, 1 line like so
ssh [email protected] -pw abc123
But when I try this from OSX terminal, I get an error Bad port 'w'
How can make this work on macOS?
I can SSH from my pc using putty, 1 line like so
ssh [email protected] -pw abc123
But when I try this from OSX terminal, I get an error Bad port 'w'
How can make this work on macOS?
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
:
ssh-keygen
. If you accept the default filenames, your ssh client will automatically try this key when it connects..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.
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?
If the above is not enough, you can install sshpass (see howto: https://stackoverflow.com/questions/32255660/how-to-install-sshpass-on-mac) then use sshpass -p YOUR-PWD ssh USER-NAME@HOST-NAME
I do this way:
cd ~/
- to jump into home dir) use: nano 'connection_name'.sh
then write this code:#!/usr/bin/expect -f
spawn ssh user_name@{ip addr or server name}
# expect "login:"
# send "{put username here}\r"
expect "password:"
send "{put password here}\r"
interact
nano ~/.bash_profile
put at the end alias connection_name="~/'connection_name'.sh"
connection_name
(connection_name - your shorthand command such as raspberry, banana, or something as you like)
I would strongly recommend using the macOS built-in
$ ssh-copy-id
will ask you to enter the password (of course, to the target system)
then,
appends the exchanged key to~/.ssh/authorized_keys
, so that you only have to validate credentials that first time
-p
in the hopes it will prompt you for a password?