-3

I want to make an alias for sudo i.e.

alias now="echo [password] | sudo -S"

but it doesn't seem to work...

I was thinking that something like the following would work

alias now="echo [password] | sudo -S ${command_line_parameter}"

but I don't know what "${command_line_parameter}" would be... Any ideas?

1 Answers1

0

This post is only aimed to answer the how to of your question, however as others suggest it, you should consider implementing your desired rules in /etc/sudoers file, something like:

james  ALL=(ALL:ALL) NOPASSWD: /bin/ls

You can't pass an argument to an alias in a way you are doing it, you can use "functions" instead:

now(){ echo $1 | sudo -S $@ }

and use it like:

now password

If you want to hardcode your password:

now(){ echo your-password | sudo -S $@ }

Which non of them are a good thing to do at all, it's like giving your password away.

Ravexina
  • 55,668
  • 25
  • 164
  • 183
  • I am well aware of the security issues with this but I am the only one using the installation and also, it is within a virtual machine. It is also just as something to be entertaining (while being functional) for me to confuse the hell out of my friends. I could have used f***ing as the alias for added fun but... I doubt that would be accepted to have in a question – James Yeoman May 27 '17 at 06:36