2

I've googled extensively but haven't found how to add a password option so I don't have to type it in manually. I've created the following alias:

alias int='sudo service network-manager restart'

But I don't want to type in my password every time, is there some command I can pass to the alias with my password?

2 Answers2

6

Echoing the password into the command works but should only be exercised in extreme cases where there's absolutely no security concerns.

However, I believe a better solution would be to make a new rule in /etc/sudoers to allow certain commands (sudo service network-manager restart in this case) to be executed without password. See the answer to this question to understand how to do it.

chin
  • 150
2

This is what I use:

alias nm='echo "abcdefg" | sudo -S service network-manager restart'

where "abcdefg" stands for my actual password. I'm the sole user of my computer and no one else has access to it. So I'm not too concerned about security.

From the sudo man page:

The -S (stdin) option causes sudo to read the password from standard input instead of the terminal device. The password must be followed by a newline character.

green
  • 14,406