SSHPass: SSH Login With Password – Command Line
source link: https://www.shellhacks.com/sshpass-ssh-login-with-password-command-line/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
SSHPass: SSH Login With Password – Command Line
A password-based authentication is often a default way to connect to a remote host over SSH.
But as it requires a user to enter a password manually, this creates some complicity if you need to automate the SSH login.
This note shows how to login over SSH by passing the password as a parameter on a command-line using the sshpass
command.
Cool Tip: Log in to a remote Linux server without entering password! Set up password-less SSH login! Read more →
SSH Login With Password
Install the sshpass
tool, that permits to set the SSH password on the command-line:
# Debian/Ubuntu/Linux Mint $ sudo apt-get install sshpass # RedHat/CentOS $ sudo yum install epel-release $ sudo yum install sshpass # macOS $ brew install hudochenkov/sshpass/sshpass
To login to a host over SSH by passing the plain-text password as a parameter, use the sshpass
command as follows:
$ sshpass -p <password> ssh <user>@<hostname> - example - $ sshpass -p P@$$w0rd ssh [email protected]
To execute a command over SSH without being prompted for a password:
$ sshpass -p <password> ssh <user>@<hostname> "<command(s)>" - example - $ sshpass -p P@$$w0rd ssh [email protected] "whoami; hostname" - sample output - root ubuntu-2004
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK