centos 7中添加一个新用户并受权的步骤详解

1.建立新用户:


建立一个用户名为:zhangbiao

  1 adduser zhangbiao 

为这个用户初始化密码,linux会判断密码复杂度,不过能够强行忽略:

   1 passwd zhangbiao  更改用户 zhangbiao 的密码 。 新的 密码: 无效的密码: 密码未经过字典检查 - 过于简单化/系统化 从新输入新的 密码: passwd:全部的身份验证令牌已经成功更新。

2.受权:


我的用户的权限只能够在本home下有完整权限,其余目录要看别人受权。而常常须要root用户的权限,这时候sudo能够化身为root来操做。我记得我曾经sudo建立了文件,而后发现本身并无读写权限,由于查看权限是root建立的。

新建立的用户并不能使用sudo命令,须要给他添加受权。

sudo命令的受权管理是在sudoers文件里的。

能够看看sudoers:

  1 whereis sudoers sudoers :
 
 /etc/sudoers /etc/sudoers.d /usr/libexec/sudoers.so /usr/share/man/man5/sudoers.5.gz

找到这个文件位置以后再查看权限:

  1 ls -l /etc/sudoers  
 
-r--r----- 1 root root 4251 9月 25 15:08 /etc/sudoers

是的,只有只读的权限,若是想要修改的话,须要先添加w权限:

   1 chmod -v u+w /etc/sudoers 
 
mode of "/etc/sudoers" changed from 0440 (r--r-----) to 0640 (rw-r-----)

而后就能够添加内容了,在下面的一行下追加新增的用户:
 
1 vim /etc/sudoers 
2 ## Allow root to run any commands anywher 
3 root ALL=(ALL) ALL
4 zhangbiao ALL=(ALL) ALL #这个是新增的用户

wq保存退出,这时候要记得将写权限收回:

  1 chmod -v u-w 
 
 /etc/sudoers mode of "/etc/sudoers" changed from 0640 (rw-r-----) to 0440 (r--r-----)

这时候使用新用户登陆,使用sudo:

  1 sudo cat /etc/passwd [sudo] password for zhangbiao: 
 
 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.

第一次使用会提示你,你已经化身超人,身负责任。并且须要输入密码才能够下一步。若是不想须要输入密码怎么办,将最后一个 ALL 修改为 NOPASSWD: ALL 。
原文连接:https://m.jb51.net/article/120366.htm
相关文章
相关标签/搜索