Bash Script for SSH Login with Password


The title “Bash Script for SSH Login with Password” means executing a bash script so you may instantly log in to the server with out the necessity to kind the SSH command or password. A bash script to automate the SSH login is useful (for sure automation) and avoids the necessity for key primarily based login setup. Nonetheless, we’re describing the methodologies to automate SSH login for issues equivalent to Raspberry Pi. The strategies for automating SSH login in these manners are usually not to be used on unmanaged internet servers (equivalent to one operating PHP, Apache2, MySQL, or WordPress and having a public IP tackle).


Bash Script for SSH Login


The simplest technique is the beneath:

Now do the steps to execute the script:

That’s in all probability liable to failure in several conditions. One other technique is by putting in a package deal named count on :

The simplest script I do know is just like the one beneath:

yourpassword written above is your actual password. You need to make it executable and run:

It really works nice for recognized hosts. Nonetheless, it can’t deal with further dialogues. I discovered the beneath script described by which addresses that difficulty :

I’ve saved the script on GitHub as gist for my utilization. You’ll be able to wget it and use it.

One other technique described to realize an analogous result’s by putting in a package deal named sshpass. The benefit of the SSH Move package deal is that you should utilize it with key-based login too.

Nonetheless, if you’d like key-based login, then carry out the beneath steps.

Press Return when prompted for passphrase. Press Return a second time to verify. There will probably be two information within the ~/.ssh listing, and mysshkey. is the general public key, you’ll put this on distant servers. mysshkey is your personal key.

Bash Script for SSH Login with Password

On the server you want to SSH into. Login to the distant server:

And you’ll be logged in with out being prompted for a password. The final technique is the most secure one.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button