sshpass (github, man page) is a tool that automatically feeds the password to ssh. The secure way to use it is this:
% echo 'correct horse battery staple' > ~/.ssh/compute_password
% chmod go-rw ~/.ssh/compute_password
% sshpass -f ~/.ssh/compute_password ssh foo@host
This will read the password from
~/.ssh/compute_password, much like a private key file without passphrase. You could put the
sshpass command in a small shell script or a shell alias to avoid typing that full command. Sadly, I haven't found a way to do this from
(It is also possible to specify the password directly on the command line to
sshpass, but this should be avoided, as it leaks the password to anyone who can do
Comparison to other methods
This approach is of course less secure than properly set up public key authentication, but you probably know that already.
It is also less secure than @grawity's answer about connection re-use, but it has the advantage of not having to enter the password interactively at all.
You could consider @grawity's answer an alternative to pubkey auth with a passphrase and private key caching (i.e.
ssh-agent). Then my answer would be an alternative to pubkey auth without a passphrase on the private key file.