Accueil > Système > How to run sudo command without a password on a Linux or Unix

How to run sudo command without a password on a Linux or Unix

20/03/2024 Categories: Système Tags: , ,
Print Friendly, PDF & Email

Source: nixCraft

I‘m a new Unix system user. How do I use sudo command without a password on a Linux or Unix-like systems?

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.

You need to consider any security consequence of allowing a sudo command execute without a password.

To run sudo command without a password:

  1. Backup your /etc/sudoers file by typing the following command:
    sudo cp /etc/sudoers /root/sudoers.bak
  2. Edit the /etc/sudoers file by typing the visudo command:
    sudo visudo
  3. 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
  4. Save and exit the file.

How do I test it?

Simply run /bin/kill to kill any process without a password:
[vivek@server ]$ sudo /bin/kill pid-here
OR
[vivek@server ]$ sudo /bin/systemctl restart httpd.service

Lire aussi:  Set Up SSH Tunneling on a Linux / Unix / BSD Server To Bypass NAT
Categories: Système Tags: , ,
Les commentaires sont fermés.