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?
2 Answers
Use sshpass, one of two forms:
sshpass -ffilename ssh user@ip # prefer this
sshpass -pPa5sw0rd ssh user@ip # avoid thiswhere 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
-por-f, but at leastsshpass1.06 in my Debian 10 allows it; yoursshpassmay 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. Usechmod 600 filenameto make the file private (root will still be able to access it though). Read about security considerations in the manual.
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