1、创建新用户
创建一个用户名为:test
[root@localhost /]# useradd test
为这个用户初始化密码,linux会判断密码复杂度,不过可以强行忽略:
[root@localhost /]# passwd test
Changing password for user test.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
2、授权
个人用户的权限只可以在本home下有完整权限,其他目录要看别人授权。而经常需要root用户的权限,这时候sudo可以化身为root来操作。我记得我曾经sudo创建了文件,然后发现自己并没有读写权限,因为查看权限是root创建的。
新创建的用户并不能使用sudo命令,需要给他添加授权。
sudo命令的授权管理是在sudoers文件里的。可以看看sudoers:
[root@localhost /]# sudoers
-bash: sudoers: command not found
[root@localhost /]# whereis 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 4328 Sep 30 2020 /etc/sudoers
是的,只有只读的权限,如果想要修改的话,需要先添加w权限:
[root@localhost /]# chmod -v u+w /etc/sudoers
mode of ‘/etc/sudoers’ changed from 0440 (r--r-----) to 0640 (rw-r-----)
然后就可以添加内容了,在下面的一行下追加新增的用户:
[root@localhos