Browse Docs

๐Ÿ›ก๏ธ sudo

/etc/sudoers

The /etc/sudoers file contains the set of UNIX operating-system privileges that the local administrator has granted to UNIX users.

In no case should this file be edited directly with vi; it must be edited with visudo.

1sudo          :  execute a command as root.
2sudo su       :  become root and stay root.
3sudoers       :  file listing the commands allowed for certain users as the superuser (or another user).
4visudo -cs    :  strict syntax check of the sudoers file.
  • sudo -i is equivalent to su - in terms of rights.
    • with sudo -i, the user password is asked.
    • with su -, the root password is asked.

Verification

1sudo -l -U <user>

Rules

1# "user" runs "sudo -u target All_the_commands"
2user server=(target) NOPASSWD: ALL

With aliases

1Host_Alias LOAD_BALANCERS = server1,server2
2
3Cmnd_Alias SET_VIP = \
4/sbin/ip addr add 192.168.10.12/20 broadcast 192.168.15.255 dev eth0 label eth0\:0, \
5/sbin/ip addr del 192.168.10.12/20 dev eth0, \
6/sbin/arping -U -c 1 -I eth0 192.168.10.12
7
8loaduser  LOAD_BALANCERS=(root) NOPASSWD: SET_VIP
9syncuser  LOAD_BALANCERS=(root) NOPASSWD: SET_VIP
Sunday, October 4, 2026 Tuesday, August 15, 2023