简体   繁体   English

“ sudo”命令如何工作?

[英]How “sudo” command works?

My understand is that sudo is executes a given command with root privileges, but I experienced that entering a command in Terminal with sudo caches the authorization. 我的理解是sudo使用root特权执行给定的命令 ,但是我体验到在终端中使用sudo输入命令会缓存授权。 How does it actually works? 它实际上如何运作?

For eg 例如

sudo fdisk -l
[sudo] password for xxxxx:

(once I authorize by entering a password, successive sudo commands are not prompting for passwords) (一旦我输入密码授权,连续的sudo命令不会提示输入密码)

sudo fdisk -l

(not prompting for password) (不提示输入密码)

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

Whether sudo is really a wrapper for su (substitute/switch user)? sudo是否真的是su (替代/切换用户)的包装器?

man sudo would tell: 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.

It also says: 它还说:

   -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.

Here goes proper detail for you: 这里有适合您的详细信息:
Yes sudo and su command is bit different: 是的sudo和su命令有点不同:
1.) When we fire su command it will act as a pure Admin (We can same permanently for that session time) 1.)当我们触发su命令时,它将充当纯管理员(我们可以在该会话时间内永久不变)
2.) Whereas, sudo command is acts as a having or assigning admin priviledges (We can say temporary for that session only) 2.)鉴于sudo命令是拥有或分配管理员权限的角色(我们只能说该会话是临时的)

Another Example: 另一个例子:
In windows system, hope you have checked right click properties like "Run as Administrator", this is same as sudo. 在Windows系统中,希望您已选中右键单击属性,例如“以管理员身份运行”,这与sudo相同。
And if we login or switching user to Admin, it purely acts as a Administrator for all the programs. 而且,如果我们将用户登录或切换为Admin,则它纯粹是充当所有程序的管理员。

Hope you have understood my example, this was best from my side 希望你理解我的榜样,这对我来说是最好的

In your /etc/sudoers you can edit the sudo configuration. 在/ etc / sudoers中,您可以编辑sudo配置。

There is a default timeout of authorization. 没有默认的授权超时。

You can even assign some of your user using sudo without requirement of a password. 您甚至可以使用sudo分配一些用户,而无需输入密码。 Or some user once authorized, it won't require password until you logout your system. 或者某些用户一旦获得授权,则在您注销系统之前不需要密码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM