How to Pass SSH password in Command line for Linux Servers?

(Bibin Wilson) #1

When you are working gin development machine, you might want to do ssh to several servers. If you have the ssh keys setup, then you can simply add the aliases and run those aliases when ever you wan to do ssh. However, when you have username and password, it is little tricky to add aliases with a password.

To solve this problem, you can use the sshpass utility. Follow the steps given below for the setup.

  1. Install sshpass

     sudo apt-get install sshpass

    If you get Package Linux-image-generic is not configured yet. error, then execute the following command.

     apt-get autoremove
  2. Once installed, you can pass the passord using the following syntax.

     sshpass -p ssh_password ssh [email protected]

Hope this helps. Let me know in case if you have some other hacks to achieve this.