(CentOS is an Enterprise Linux distribution based on a rebuild of the freely available sources from Red Hat Enterprise Linux. The rebuild process strives to remove encumbered trademarked images and make other minimal changes as to the binary update network, but should generally perform identically to the upstream's product, even to matching behaviors considered un-addressed bugs. Each CentOS version is supported for up to 10 years (by means of security updates -- the duration of the support interval has varied over time as the release policy as to upstream Source RPM changes). A new CentOS version is released approximately every 2 years and each CentOS version is periodically updated (roughly every 6 months) to support newer hardware. This results in a secure, low-maintenance, reliable, predictable and reproducible Linux environment.)
sudo是linux系统管理指令,是允许系统管理员让普通用户执行一些或者全部的root命令的一个工具,如halt,reboot,su等等。这样不仅减少了root用户的登陆 和管理时间,同样也提高了安全性。
(/etc/sudoers:Sudoers allows particular users to run various commands as the root user, without needing the root password.)
刚用vMware Workstation装了CentOS,之前用的是ubuntu,发现与之不同地,默认的用户没有sudo权限(sudo是需要授权许可的)。执行sudo命令时会提示“XXX is not in the sudoers file”。而且用vmware easy install的情况下,root密码是和默认用户密码一样的。
在CentOS的wiki网站中讲到了“How To Become Root”
(http://wiki.centos.org/TipsAndTricks/BecomingRoot)。
其中有一段:
You don't need to be root every time you want to run some specific administrative tasks. Thanks to sudo, you can run some or every command as root. Once sudo is installed (package name: sudo), you can configure it by running 'visudo' as root. Basically, it runs $EDITOR (vim as default) on /etc/sudoers, but it is not recommended to do it manually. If you are on a desktop computer, you will want to be able to do almost everything.
So, the quick and dirty way to use sudo would be to add at the end of the sudoers file :
bob ALL=(ALL) ALL (#即:用户账户 登录的主机=(可变的身份)可执行的命令)
where bob is the name of the user. Save (press escape, then type ZZ), and you are ready to go. Log in as bob, and run for example:
$sudo yum update
sudo will ask for a password. This password is bob's password, and not root's password, so be careful when you give rights to a user with sudo.
由此可知,要将user添加到sudoers文件里,只需修改/etc/sudoers即可。可以用root登录,找到该文件后直接修改;也可以root身份执行visudo,在vim编辑器中修改。
我用第二种方法:
su -,输入root秘密,默认与装系统时的user密码一样;
visudo,在vim界面中输入"i"进入编辑模式,在文件末尾添加"xxx ALL=(ALL) ALL"(xxx为用户名),
保存退出:先按一 下Esc键,然后输入":wq"。
此外,该文段后续的内容中还提到了sudo的更多功能,如在用户账户的字段前加上%,就可以代表用户组的身份;在可执行命令的字段前加上“NOPASSWD”则可以使其执行sudo时不需要输入密码:
But sudo can do more. We can allow a user or group of users to run only one command, or a group of commands...