$ sudo tail -5 /var/log/secure [sudo] password for daygeek: Mar 17 07:01:56 CentOS7 sudo: daygeek : TTY=pts/0 ; PWD=/home/daygeek ; USER=root ; COMMAND=/bin/tail -5 /var/log/secure Mar 17 07:01:56 CentOS7 sudo: pam_unix(sudo:session): session opened for user root by daygeek(uid=0) Mar 17 07:01:56 CentOS7 sudo: pam_unix(sudo:session): session closed for user root Mar 17 07:05:10 CentOS7 sudo: daygeek : TTY=pts/0 ; PWD=/home/daygeek ; USER=root ; COMMAND=/bin/tail -5 /var/log/secure Mar 17 07:05:10 CentOS7 sudo: pam_unix(sudo:session): session opened for user root by daygeek(uid=0)
$ sudo tail -5 /var/log/auth.log [sudo] password for 2gadmin: Mar 17 20:39:47 Ubuntu18 sudo: 2gadmin : TTY=pts/0 ; PWD=/home/2gadmin ; USER=root ; COMMAND=/bin/bash Mar 17 20:39:47 Ubuntu18 sudo: pam_unix(sudo:session): session opened for user root by 2gadmin(uid=0) Mar 17 20:40:23 Ubuntu18 sudo: pam_unix(sudo:session): session closed for user root Mar 17 20:40:48 Ubuntu18 sudo: 2gadmin : TTY=pts/0 ; PWD=/home/2gadmin ; USER=root ; COMMAND=/usr/bin/tail -5 /var/log/auth.log Mar 17 20:40:48 Ubuntu18 sudo: pam_unix(sudo:session): session opened for user root by 2gadmin(uid=0)
或者,我们可以通过添加用户到 admin 组来执行相同的操作。
运行下面的命令,添加用户到 admin 组。
1
# usermod -aG admin user1
我们可以通过下面的命令来确定这一点。
1 2
# getent groupadmin admin:x:1011:user1
让我们看看输出信息。
1 2 3 4
$ sudo tail -2 /var/log/auth.log [sudo] password for user1: Mar 17 20:53:36 Ubuntu18 sudo: user1 : TTY=pts/0 ; PWD=/home/user1 ; USER=root ; COMMAND=/usr/bin/tail -2 /var/log/auth.log Mar 17 20:53:36 Ubuntu18 sudo: pam_unix(sudo:session): session opened for user root by user1(uid=0)
$ sudo systemctl restart apache2 [sudo] password for user2:
$ sudo tail -f /var/log/auth.log [sudo] password for user2: Mar 17 21:01:04 Ubuntu18 systemd-logind[559]: New session 22 of user user2. Mar 17 21:01:04 Ubuntu18 systemd: pam_unix(systemd-user:session): session opened for user user2 by (uid=0) Mar 17 21:01:33 Ubuntu18 sudo: user2 : TTY=pts/0 ; PWD=/home/user2 ; USER=root ; COMMAND=/bin/systemctl restart apache2
方法 3:在 Linux 中如何使用 /etc/sudoers 文件为普通用户授予超级用户访问权限?
$ sudo systemctl restart mariadb [sudo] password for user3:
$ sudo tail -f /var/log/auth.log [sudo] password for user3: Mar 17 21:12:32 Ubuntu18 systemd-logind[559]: New session 24 of user user3. Mar 17 21:12:49 Ubuntu18 sudo: user3 : TTY=pts/0 ; PWD=/home/user3 ; USER=root ; COMMAND=/bin/systemctl restart mariadb Mar 17 21:12:49 Ubuntu18 sudo: pam_unix(sudo:session): session opened for user root by user3(uid=0) Mar 17 21:12:53 Ubuntu18 sudo: pam_unix(sudo:session): session closed for user root Mar 17 21:13:08 Ubuntu18 sudo: user3 : TTY=pts/0 ; PWD=/home/user3 ; USER=root ; COMMAND=/usr/bin/tail -f /var/log/auth.log Mar 17 21:13:08 Ubuntu18 sudo: pam_unix(sudo:session): session opened for user root by user3(uid=0)