CentOS──xxx is not in the sudoers file

    CentOS是一个基于Red Hat Linux提供的可自由使用源代码的企业级Linux发行版本。RHEL在发行时,提供二进制和源代码两种发行方式,CentOS就是将RHEL发行的源代码重新编译一次,形成一个可使用的二进制版本。因此,CentOS可以得到RHEL的所有功能,甚至是更好的软件。但CentOS 并不向用户提供商业支持,当然也不负上任何商业责任。
   (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...



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值