Add a new user and authorize in CentOS 7

Create new user

Create a username: linuxidc

[root@localhost ~]# adduser linuxidc

To initialize the password for this user, linux will judge the password complexity, but it can be ignored forcibly:

[root@localhost ~]# passwd linuxidc
更改用户 zhangbiao 的密码 。
新的 密码:
无效的密码: 密码未通过字典检查 - 过于简单化/系统化
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。

Authorize

The permissions of individual users can only have full permissions under this home, and other directories need to be authorized by others. However, the privileges of the root user are often required. At this time, sudo can be incarnated as root to operate. I remember that I used sudo to create a file and then found that I didn't have read and write permissions because the view permissions were created by root.

The newly created user cannot use the sudo command and needs to add authorization to him.

The authorization management of the sudo command is in the sudoers file. Take a look at sudoers:

[root@localhost ~]# sudoers
bash: sudoers: 未找到命令...
[root@localhost ~]# whereis sudoers
sudoers: /etc/sudoers /etc/sudoers.d /usr/libexec/sudoers.so /usr/share/man/man5/sudoers.5.gz

Check the permissions after finding the file location:

[root@localhost ~]# ls -l /etc/sudoers
-r--r----- 1 root root 4251 925 15:08 /etc/sudoers

Yes, only read-only permissions, if you want to modify, you need to add w permissions first:

[root@localhost ~]# chmod -v u+w /etc/sudoers
mode of "/etc/sudoers" changed from 0440 (r--r-----) to 0640 (rw-r-----)

Then you can add content, appending the new user under the following line:

[root@localhost ~]# vim /etc/sudoers


## Allow root to run any commands anywher  
root    ALL=(ALL)       ALL  
linuxidc  ALL=(ALL)       ALL  #这个是新增的用户

wq save and exit, remember to take back the write permission at this time:

[root@localhost ~]# chmod -v u-w /etc/sudoers
mode of "/etc/sudoers" changed from 0640 (rw-r-----) to 0440 (r--r-----)

At this time, log in with the new user and use sudo:

[linuxidc@localhost ~]$ sudo cat /etc/passwd
[sudo] password for linuxidc: 

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.

The first time you use it will prompt you that you have become a superman and are responsible. And you need to enter a password to go to the next step. If you don't want to need to enter a password, change the last one ALLto NOPASSWD: ALL.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326258832&siteId=291194637