Details of the steps to add a new user and authorize in centos 7

  • 2020-06-12 11:40:21
  • OfStack

preface

Recently, I installed an centos in my laptop. I want to let others log in and access it. It is not so good to use my own account, so I plan to create a new user for him. Find the site this convenient information is less, so their own steps to share the summary, not to say more, to see a detailed introduction:

Create a new user

Create 1 user name: zhangbiao


[root@localhost ~]# adduser zhangbiao

When you initialize a password for this user, linux determines the complexity of the password, but you can force it to ignore it:


[root@localhost ~]# passwd zhangbiao
 Change user  zhangbiao  The password   . 
 The new   Password: 
 Invalid password:   The password failed the dictionary check  -  Oversimplification / systematic 
 Reenter the new   Password: 
passwd : All authentication tokens have been successfully updated. 

authorization

Individual user permissions can only have full permissions under this home, other directories to see others authorization. While root user permissions are often required, sudo can be changed to root to operate. I remember when sudo created the file and found out that I didn't have read or write access because the view access was created by root.

The newly created user cannot use the sudo command and needs to be authorized.

Authorization management for the sudo command is in the sudoers file.

Check out sudoers:


[root@localhost ~]# sudoers
bash: sudoers:  No command found ...
[root@localhost ~]# whereis sudoers
sudoers: /etc/sudoers /etc/sudoers.d /usr/libexec/sudoers.so /usr/share/man/man5/sudoers.5.gz

Find the file location before viewing permissions:


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

Yes, only read-only permissions, if you want to change, 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-----)

You can then add content by appending new users at the bottom of line 1:


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


## Allow root to run any commands anywher 
root ALL=(ALL)  ALL 
zhangbiao ALL=(ALL)  ALL # This is the new user 

wq save exit and remember to take back write permission:


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

At this point, use the new user to log in. Use sudo:


[zhangbiao@localhost ~]$ 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.

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

conclusion

reference

Centos 7 adds users


Related articles: