How to specify password in ssh command

Solution 1:

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.