- Install the application sshpass:
sudo apt install sshpass
- Make sure to set in your
~/.ssh/config
file the following options to prevent ssh from using your pubkey:
PreferredAuthentications password
PubkeyAuthentication no
PasswordAuthentication yes
ServerAliveInterval 10
- Run the following command to create your new "sshpass" file with your ssh password.
echo yourpassword > .sshpass
- Encrypt the "sshpass" file with gpg:
gpg -c ~/.sshpass
- Remove original decrypted version of the file:
rm -rf ~/.sshpass
Using with an $SSHPASS environmental variable:
export $SSHPASS=your_password
sshpass -e ssh [email protected]
Using it with a .sshpass (or any named) file:
sshpass -f fileNameHere ssh user@server
Using it with GPG for encryption:
gpg -d -q .sshpass.gpg > fifo; sshpass -f fifo ssh user@server
Using it with rsync:
rsync --rsh="sshpass -e ssh -l username" server.example.com:/var/www/html/ /backup/
Here are some handy aliases for using a GPG encrypted password file:
alias ssh='gpg -d -q ~/.sshpasswd.gpg > fifo; sshpass -f fifo ssh'
alias scp='gpg -d -q ~/.sshpasswd.gpg > fifo; sshpass -f fifo scp'