Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to create and delete users under Linux

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you how to create and delete users under Linux, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's learn about it!

There are two main ways to create users under Linux: adduser and useradd. Their differences and main uses are as follows:

Adduser

The use of adduser is simple, as long as adduser+username is required, as follows:

Sudo adduser alvin

This command is actually a perl script, and its underlying layer is to call the useradd command. Many online tutorials say it can interact with people, but now some distributions (such as centOS) have been improved to create users without tedious interaction.

The adduser command automatically creates the user's home directory and specifies the shell version. However, some distributions will require you to set the user password while creating the user, while others will not, need to set the password manually.

Create a password for the user as follows:

Sudo passwd alvin

Useradd

Useradd is a relatively complex command, and it has higher degrees of freedom. If you just run useradd+username, it will create a three-no user, that is, no user home directory, no specified shell version, no password.

In order to successfully create a user, we also need to refine its parameters through some options. The common options for the useradd command are as follows:

-c: add the remarks. The remarks text will be saved in the remarks field of passwd

-d: specify the starting directory when the user logs in

-D: change the default value

-e: specify the validity period of the account

-f: specify how many days after the password expires to close the account

-g: specify the group to which the user belongs

-G: specify the additional group to which the user belongs

-m: automatically set up the user's login directory

-M: do not automatically create a user's login directory

-n: cancels the establishment of a group with the user name

-r: set up a system account

-s: specify the shell that the user will use after logging in

-u: specify the user id.

For us ordinary users, the more commonly used options are the three above marked red. For managers, all of the above options need to be mastered. At present, we focus on the above three options for red.

The-d option is used to specify the user's home directory, that is, the directory in which the user logs in. For example:-d / home/alvin, which specifies that the user's home directory is / home/alvin. The-d option is usually used with the-m option, which is created automatically if the specified directory does not exist.

The-s option specifies the user's default shell version. If not set, the default version is / bin/sh. So the classic usage when we use useradd to create new users is as follows:

Sudo useradd alvin-m-d / home/alvin-s / bin/bash

In this way, the user can successfully create it, but there is still no password. The way to create a password is still using the passwd command, so I won't repeat it here.

Userdel

Delete the user, just "userdel user name". It's best to delete the files it left on the system, too, using the "userdel-r user name".

Sudo userdel-r alvin above is all the content of the article "how to create and delete users under Linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report