Zhenguo Zhang's Blog
Sharing makes life better
[Linux] Input password automatically

In this post, I will introduce an approach to input password programatically, which is useful if a repeated command needs password.

Note: this approach is subject to the risk of exposing your passwords to others, so use it with caution.

Let’s use sudo as an example. Normally when you type

1
sudo ls

It will prompt for a password if you set one.

However, if you type

1
sshpass 'your-password' sudo ls

Then the passord is fed into the command directly. Here the command sshpass is from a package sshpass, which can be installed with

1
sudo apt-get install sshpass

Hope that this tip helps.


Last modified on 2019-10-07

Comments powered by Disqus