LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1717|回复: 11

sudo命令的妙用

[复制链接]
发表于 2003-12-5 22:22:09 | 显示全部楼层 |阅读模式
[code]
原因1.
    使用linux时总会时不进对linux进行管理,但管理权限都是root的。
但我们知道,sudo命令可以用来改变用户身份(有效uid)
所有,我们可以用sudo命令来重造一个root用户
[code]
原因2.
    因为我习惯于在普通用户名下处理一般性事务,所以用root身份进入linux时很不习惯,比如:打入ls,显示的目录和普通文件是同样色彩的(这是因为默认的root帐号中没有设alias机制,而普通用户则有alias ls= ls --color=tty这类设置,虽没什么不便,但总是不习惯。
[code]
解决方法:
    1。用root帐号登录(或用其他方式得到root权限)
    2。打开/etc/sudoer文件
    3。另起一行,加入sa  all  NOPASSWORD:ALL
        其中sa 为普通用户帐号,
    4。用sa登录,在$提示符下键入sudo bash
[code]
怎样,$变为#了吧?要回到普通用户模式,请键入exit
注:事实上,这并非真的让你变为root,你打入who am i,它会告诉你
sa tty1...,也就是说你的身份还是sa,但你的确得到了root权限。你几乎可以做任何root可以做的事情(事实上,你的真实uid还是sa的.但你的euid是root,在linux下,很少有调用要用到real uid)。
[code]
这样做的另一个好入是你可以防止木马程序窍取你的root密码。
发表于 2003-12-5 22:42:13 | 显示全部楼层
应该是编辑/etc/sudoers这个文件吧~~
 楼主| 发表于 2003-12-6 10:39:05 | 显示全部楼层
是/etc/sudoers
因为我比较关注内核,所以会把这些应用层上的知细节遗忘,高谢谢更正
 楼主| 发表于 2003-12-6 10:39:05 | 显示全部楼层
是/etc/sudoers
因为我比较关注内核,所以会把这些应用层上的知细节遗忘,高谢谢更正
 楼主| 发表于 2003-12-6 10:41:56 | 显示全部楼层
是/etc/sudoers
因为我比较关注内核,所以会把这些应用层上的知细节遗忘,谢谢更正
发表于 2003-12-6 10:52:41 | 显示全部楼层
编译/etc/sudoers的命令应该是visudoer
 楼主| 发表于 2003-12-6 10:55:47 | 显示全部楼层

也可以用vi /etc/sudoers

能用vi   我尽可用vi
发表于 2003-12-6 12:13:15 | 显示全部楼层
visudo
发表于 2004-3-10 13:20:12 | 显示全部楼层

回复: sudo命令的妙用

最初由 folklore 发表
[code]
原因1.
    使用linux时总会时不进对linux进行管理,但管理权限都是root的。
但我们知道,sudo命令可以用来改变用户身份(有效uid)
所有,我们可以用sudo命令来重造一个root用户
[code]
原因2.
    因为我习惯于在普通用户名下处理一般性事务,所以用root身份进入linux时很不习惯,比如:打入ls,显示的目录和普通文件是同样色彩的(这是因为默认的root帐号中没有设alias机制,而普通用户则有alias ls= ls --color=tty这类设置,虽没什么不便,但总是不习惯。
[code]
解决方法:
    1。用root帐号登录(或用其他方式得到root权限)
    2。打开/etc/sudoer文件
    3。另起一行,加入sa  all  NOPASSWORD:ALL
        其中sa 为普通用户帐号,
    4。用sa登录,在$提示符下键入sudo bash
[code]
怎样,$变为#了吧?要回到普通用户模式,请键入exit
注:事实上,这并非真的让你变为root,你打入who am i,它会告诉你
sa tty1...,也就是说你的身份还是sa,但你的确得到了root权限。你几乎可以做任何root可以做的事情(事实上,你的真实uid还是sa的.但你的euid是root,在linux下,很少有调用要用到real uid)。
[code]
这样做的另一个好入是你可以防止木马程序窍取你的root密码。


sa  all  NOPASSWORD:ALL

两个ALL 什么意思请解释一下好吗
哪个是 all command
发表于 2005-3-10 20:42:05 | 显示全部楼层
管理员见谅,不要删此贴。搜遍了没找到全面的sudo.说明。在此copy了一些,觉得挺全的。这样一个常用的命令竟没有一个全面的说明,也许是我没找到。~

详见:http://www.linuxhomenetworking.com/linux-hn/addusers.htm
下面是主要的,粘贴过来好用:
The /etc/sudoers File

The /etc/sudoers file contains all the configuration and permission parameters needed for sudo to work. There are a number of guidelines that need to be followed when editing it with visudo.
General /etc/sudoers Guidelines

The /etc/sudoers file has the general format shown in Table 9-1.



                                  Table 9-1 Format of the /etc/sudoers File

General sudoers File Record Format

                           usernames/group servername = (usernames command can be run as) command



There are some general guidelines when editing this file:

>       Groups are the same as user groups and are differentiated from regular users by a % at the beginning. The Linux user group "users" would be represented by %users.

>       You can have multiple usernames per line separated by commas.

>       Multiple commands also can be separated by commas. Spaces are considered part of the command.

>       The keyword ALL can mean all usernames, groups, commands and servers.

>       If you run out of space on a line, you can end it with a back slash (\) and continue on the next line.

>       sudo assumes that the sudoers file will be used network wide, and therefore offers the option to specify the names of servers which will be using it in the servername position in Table 9-1. In most cases, the file is used by only one server and the keyword ALL suffices for the server name.

>       The NOPASSWD keyword provides access without prompting for your password.
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表