How to automatically use the password in a bash script

I run Xubuntu in dual-boot with Windows 10. The C: drive (/dev/sda1 – label WinC) that have windows can not be mounted (due to fast startup feature of Windows 10) unless I use some command from the terminal.

sudo mount -t ntfs-3g -o ro /dev/sda1 /media/user/WinC

For ease, I have created a launcher (and another bash script) to run this command when I double click on it.

mountC

Still, as it has “sudo”, it prompts for the password. It is quite annoying for me as I just typed my password few seconds ago for logging in to the computer.

The solution is really really insecure and bad practice, still it gets me going, which is nice.

What I was looking for was to store the password inside a script (in plain text, yeah, its bad practice, seriously!) so that I don’t have to type it everytime the script runs.
Thanks to this post in StackOverflow, I remembered that -S switch takes the input from STDIN.

All needed to do is to modify the command above to this:

echo "MyP@$$W0RD" | sudo mount -t ntfs-3g -o ro /dev/sda1 /media/user/WinC

where, MyP@$$W0RD is the password.

Again, it’s really a bad practice (security-wise), and you are a terrible terrible person if you do this.🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s