Home >Operation and Maintenance >CentOS >How to create a new username and password under centos

How to create a new username and password under centos

WJ
WJOriginal
2020-06-02 16:20:1318955browse

How to create a new username and password under centos

How to create a new username and password under centos?

1. Create a new user

1. Create a new user: prefma

[root@localhost ~]# adduser prefma

2. Create an initialization password for the new user

[root@localhost~]# passwd prefma
Changing password for user prefma.
New password:             # 输入密码
Retype new password:      # 再次输入密码
passwd: all authentication tokens updated successfully.

2. Authorization

Individual users can only have full permissions under this home. Other directories require authorization from others. Root user permissions are often required and can be granted by modifying the sudoers file.

The newly created user cannot use the sudo command, and authorization needs to be added to him.

1. Find the sudoers file path and grant permissions

1 [root@localhost~]# whereis sudoers                     # 查找sudoers文件路径
2 sudoers: /etc/sudoers /etc/sudoers.d /usr/share/man/man5/sudoers.5.gz
3 [root@localhost~]# ls -l /etc/sudoers                  # 查看权限
4 -r--r----- 1 root root 3938 Sep  6  2017 /etc/sudoers  # 只有读权限
5 [root@localhost~]# chmod -v u+w /etc/sudoers           # 赋予读写权限
6 mode of ‘/etc/sudoers’ changed from 0440 (r--r-----) to 0640 (rw-r-----)

2. Modify the sudoers file

Enter the command vim /etc/sudoers Modify the sudoers file. Add new user information:

## Allow root to run any commands anywhere
root ALL=(ALL) ALL
prefma ALL=(ALL) ALL #这个是新用户

Then enter the command wq! to save the changes.

3. Withdraw permissions

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

4. New user login

Create a new connection, log in with the newly created user, and verify, for example:

[prefma@localhost~]$ pwd
/home/prefma
[prefma@localhost~]$ ls -l /etc/sudoers
-r--r----- 1 root root 3995 Oct 16 22:42 /etc/sudoers

Related reference: centOS tutorial

The above is the detailed content of How to create a new username and password under centos. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn