一、新建用户并登陆
为什么要新建用户?
因为root的权限太多,不方便多人多角色使用,用root用户登录进行操作比较敏感,所以添加一个用户。
01. 新建用户
1、创建一个新用户:danyang
[root@localhost ~]# adduser danyang
2. 为新用户创建初始化密码
[root@localhost~]# passwd danyang
Changing password for user danyang.
New password: # 输入密码
Retype new password: # 再次输入密码
passwd: all authentication tokens updated successfully.
02. 授权
个人用户的权限只可以在本home下有完整权限,其他目录需要别人授权。经常需要root用户的权限,可以通过修改sudoers文件来赋予权限。
新创建的用户并不能使用sudo命令,需要给他添加授权。
1、查找sudoers文件路径并赋予权限
[root@localhost~]# whereis sudoers # 查找sudoers文件路径
sudoers: /etc/sudoers /etc/sudoers.d /usr/share/man/man5/sudoers.5.gz
[root@localhost~]# ls -l /etc/sudoers # 查看权限
-r--r----- 1 root root 3938 Sep 6 2017 /etc/sudoers # 只有读权限
[root@localhost~]# chmod -v u+w /etc/sudoers # 赋予读写权限
mode of ‘/etc/sudoers’ changed from 0440 (r--r-----) to 0640 (rw-r-----)
2、修改sudoers文件
输入命令 vim /etc/sudoers 修改sudoers文件,添加新用户信息:
\## Allow root to run any commands anywhere
root ALL=(ALL) ALL
danyang ALL=(A