Languages
[Edit]
EN

Bash - run command on server over SSH and automatically enter password

6 points
Created by:
Nataniel-Barclay
289

In this short article, we would like to show how to run command on server over SSH and automatically enter password in Bash.

By default ssh command doesn't let to insert a password as a parameter, the solution is to use sshpass or plink command.

Quick solution:

plink -pw user_password user@$my-domain.com "command_to_run -arg1 -arg2 -argN"

Note: plink is available under Windows and Linux - check the installation section.

 

Practical example

plink -pw my_secret_password john@$my-domain.com "cd / && ls -al"

plink installation

Under Windows, you can use putty installer (go to MSI (‘Windows Installer’) section).

Under Debian based Linux run:

sudo apt-get update
sudo apt-get install plink

See also

  1. Bash - run remote command as super user using ssh connection with plink command

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join