How to create and manage user accounts on Linux

PHPz
Release: 2023-07-06 21:01:38
Original
6753 people have browsed it

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 <用户名>
Copy after login

For example, create a user named "testuser":

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

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

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

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

useradd -p 123456 testuser2
Copy after login

2. Manage user accounts

  1. Delete users :
userdel <用户名>
Copy after login

For example, to delete user "testuser":

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

For example, to disable user "testuser2":

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

For example, unban user "testuser2":

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

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

passwd testuser
Copy after login
Copy after login

3. Other user management related commands

  1. Switch users:
su <用户名>
Copy after login

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

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

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

finger testuser
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!