How to specify password in ssh command

From the terminal I type: ssh user@ip and then it prompts for a password.
Is there a way to specify the password in the ssh command itself?

0

2 Answers

Use sshpass, one of two forms:

sshpass -ffilename ssh user@ip # prefer this
sshpass -pPa5sw0rd ssh user@ip # avoid this

where your password is literally Pa5sw0rd or it is in the first line of the file filename. Notes:

  • In the manual there is no space after -p or -f, but at least sshpass 1.06 in my Debian 10 allows it; your sshpass may or may not.
  • If your password contains characters your shell will interpret (like $, ' or ;) then you should quote it properly in the command line (but not in the file).
  • Avoid -p. Use chmod 600 filename to make the file private (root will still be able to access it though). Read about security considerations in the manual.
3

The correct way to do this, is to switch from password authentication to a public/private key pair. This typically needs no reconfiguration at all and is quite easy.

Step 1: If you do not have a key, create one: ssh-keygen will do that for you

Step 2: Authorize this key on the remote host: Run ssh-copy-id user@ip once, using your password

Step 3: From now on ssh user@ip will no longer ask for your password

3

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like