“sudo”命令如何工作?

时间:2013-09-04 10:40:10

标签: linux ubuntu terminal ubuntu-12.04 sudo

我的理解是 sudo 是以root权限执行给定的命令,但我经历过在 sudo 缓存中输入终端中的命令授权。它是如何实际运作的?

例如

sudo fdisk -l
[sudo] password for xxxxx:

(一旦我通过输入密码授权,连续的sudo命令不会提示输入密码)

sudo fdisk -l

(不提示输入密码)

sudo mount -t vfat /dev/sda1 /media/test

sudo 是否真的是 su (替换/切换用户)的包装?

3 个答案:

答案 0 :(得分:7)

man sudo会说:

   Security policies may support credential caching to allow the user to
   run sudo again for a period of time without requiring authentication.
   The sudoers policy caches credentials for 15 minutes, unless overridden
   in sudoers(5).  By running sudo with the -v option, a user can update
   the cached credentials without running a command.

它还说:

   -k [command]
               When used alone, the -k (kill) option to sudo invalidates
               the user's cached credentials.  The next time sudo is run a
               password will be required.  This option does not require a
               password and was added to allow a user to revoke sudo
               permissions from a .logout file.  Not all security policies
               support credential caching.

               When used in conjunction with a command or an option that
               may require a password, the -k option will cause sudo to
               ignore the user's cached credentials.  As a result, sudo
               will prompt for a password (if one is required by the
               security policy) and will not update the user's cached
               credentials.

答案 1 :(得分:0)

这里有适当的细节:
是的sudo和su命令有点不同:
1.)当我们解雇su命令时,它将作为一个纯粹的管理员(我们可以在那个会话时间永久地相同)
2.)然而,sudo命令是作为拥有或分配管理员权限的行为(我们可以说仅对该会话具有临时性)

另一个例子:
在Windows系统中,希望您已经选中了“以管理员身份运行”等右键单击属性,这与sudo相同 如果我们登录或切换用户到管理员,它纯粹充当所有程序的管理员。

希望你能理解我的榜样,这在我身边是最好的

答案 2 :(得分:0)

在/ etc / sudoers中,您可以编辑sudo配置。

默认超时授权。

您甚至可以使用sudo指定一些用户而无需密码。 或者一些用户一旦获得授权,在您退出系统之前不需要密码。