Home >Operation and Maintenance >Linux Operation and Maintenance >How to create and manage user accounts on Linux

How to create and manage user accounts on Linux

PHPz
PHPzOriginal
2023-07-06 21:01:386981browse

How to create and manage user accounts on Linux

Overview:
In the Linux operating system, the creation and management of user accounts is one of the important tasks of the system administrator. By creating and managing user accounts, you can control user access and permissions to system resources. This article will introduce how to create and manage user accounts on Linux, including operations such as creating users, deleting users, disabling users, and changing user passwords. It also comes with code examples.

1. Create a user account

  1. Use the useradd command to create a user:
useradd <用户名>

For example, create a user named "testuser":

useradd testuser
  1. Set user password:
passwd <用户名>

For example, set the password of user "testuser":

passwd testuser
  1. Set password when creating user:
useradd -p <密码> <用户名>

For example, create a user named "testuser2" with a password of "123456":

useradd -p 123456 testuser2

2. Manage user accounts

  1. Delete users :
userdel <用户名>

For example, to delete user "testuser":

userdel testuser
  1. Disable user:
usermod -L <用户名>

For example, to disable user "testuser2":

usermod -L testuser2
  1. Unban user:
usermod -U <用户名>

For example, unban user "testuser2":

usermod -U testuser2
  1. Change user password:
passwd <用户名>

For example, change the password of user "testuser":

passwd testuser

3. Other user management related commands

  1. Switch users:
su <用户名>

For example, switch to the identity of user "testuser":

su testuser
  1. View the current user:
whoami
  1. View the list of currently logged in users:
w
  1. Switch to the root user:
su -
  1. View the user's detailed information:
finger <用户名>

For example, view the user "testuser" Detailed information:

finger testuser

Conclusion:
Through the introduction of this article, we can learn how to create and manage user accounts on Linux. System administrators can easily perform these operations with the appropriate commands and options. When you need to provide access and permissions to a new user, you can use the useradd command to create a user and set a password. When the user no longer needs to access the system or the account is abused, it can be disabled or deleted through the userdel or usermod command. At the same time, the user password can also be modified through the passwd command. These operations can be completed in the terminal or shell, and user accounts can also be managed in batches through scripts and batch processing. I hope this article is helpful to your user management on Linux.

The above is the detailed content of How to create and manage user accounts on Linux. 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