Some times you may need to run a command with root privileges, but you do not want to type a password using sudo command. This is useful for scripting or any other purpose. This can be achieved by editing /etc/sudoers file and setting up correct entries. ou need to consider any security consequence of allowing a sudo command execute without a password.
To run sudo command without a password:
- Backup your /etc/sudoers file by typing the following command:
sudo cp /etc/sudoers /root/sudoers.bak
- Edit the /etc/sudoers file by typing the visudo command:
sudo visudo
- Append/edit the line as follows in the /etc/sudoers file for user named 'vivek' to run '/bin/kill' and 'systemctl' commands:
vivek ALL = NOPASSWD: /bin/systemctl restart httpd.service, /bin/kill
- Save and exit the file.
How do I test it?
Simply run /bin/kill to kill any process without a password:
OR
[vivek@server ]$ sudo /bin/kill pid-here
OR
[vivek@server ]$ sudo /bin/systemctl restart httpd.service
For more info read man pages: sudoers(5), visudo(8)
0 comments:
Post a Comment