aliyun.CentOS7.新建用户并授权.2017-09-2
2017-09-26 本文已影响0人
小异_Summer
创建新用户
[~]# adduser XXX
[~]# passwd XXX
Changing password for user XXX.
New password:
BAD PASSWORD: The password is shorter than 7 characters
Retype new password:
passwd: all authentication tokens updated successfully.
授权
- 个人用户的权限只可以在本home下有完整权限,其他目录要看别人授权。经常需要root用户的权限,sudo可以化身为root来操作。
- 新创建的用户并不能使用sudo命令,需要添加授权。
- sudo命令的授权管理是在sudoers文件里的。
[~]# whereis sudoers
sudoers: /etc/sudoers /etc/sudoers.d /usr/libexec/sudoers.so /usr/share/man/man5/sudoers.5.gz
[~]# ls -l /etc/sudoers
-r--r----- 1 root root 3925 Sep 25 00:13 /etc/sudoers
[~]# chmod -v u+w /etc/sudoers
mode of ‘/etc/sudoers’ changed from 0440 (r--r-----) to 0640 (rw-r-----)
[~]# vim /etc/sudoers
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
XXX ALL=(ALL) ALL
[~]# chmod -v u-w /etc/sudoers
mode of ‘/etc/sudoers’ changed from 0640 (rw-r-----) to 0440 (r--r-----)
- 使用新用户登陆,提示已拥有权限,且需要输入密码才能进行下一步。
$ sudo cat /etc/passwd
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.
[sudo] password for XXX: