Keywordslinux linux user management linux user management commands
For our own system, there is a super user root by default, and a normal user, which is the user name we set when we install the operating system, for example, mine is called elliot. In fact, there are only two users, and we don't have to worry about how to add users, delete users, etc. But considering that we might want to change the user name, change the user password, etc., I still decided to introduce some of these, friends who are not interested can not read it, and it will not affect your normal use of the
Linux system.
Another point is that
Linux systems also have a server version. Generally, the same server will be used by many people, so an ordinary user will be created for everyone who uses it. Okay, let's take a look at how it works.
1. useradd command
We use the useradd command to create a new user. Let's look at several important parameters below.
-d account home directory (copied in /etc/skel)
-m creates the home directory at the same time (by default it takes effect when the user is first created)
-c full name (description)
-e account expired YYYY_MM_DD
-N does not create a group account with the same name
-g specifies the primary group (must exist)
-G extra group
Looking at the above description, there will definitely be people in the cloud and can't understand it. Let's look at an example of creating a new user:
sudo useradd -d /home/chaojun -m chaojun: After this command is executed, we create a new user chaojun, and at the same time create the chaojun user's home directory /home/chaojun.
It should be noted here that the account can be up to 32 characters long and the files in the user's home directory are copied from /etc/skel. Execute ll /etc/skel to see the files contained in it.
2. Manage users
Now that a new user is added, there are multiple users in our system. How does the operating system manage our multiple users? In fact, under the
Linux system, there is an account database file: /etc/passwd, let's take a look at the contents of it: enter: cat /etc/passwd in the terminal to see it.
Another user database file is /etc/shadow, we can see the contents by entering the command in the terminal: sudo cat /etc/shadow.
3. Set account password passwd chaojun -l Lock account password! -u unlock account -d Delete password (the account can log in without a password) -n/-x password minimum/maximum usage period -w Warn a few days before the password expires -i Lock the account after a few days after the password expires -e The password expires immediately (you must change the password for the next login) -S View the password status of the account (L lock, P activity, N no password)
4. Add account adduser chaojun Perl script based on useradd Not all Linux distributions include Guided operation (no need to remember commands) /usr/sbin/adduser Add accounts in bulk sudo newusers users.txt user1:passwd1:::user1:/home/user1:/bin/bash user2:passwd2:::user2:/home/user2:/bin/bash
5. Delete account userdel chaojun The user home directory was not deleted at the same time Make file backups rm -rf /home/chaojun delete user home directory userdel -r chaojun deletes its home directory while deleting the account
6. Switch account
su needs to enter the root password (default failure) sudo su Enter the current account password (the current account belongs to the sudo group) sudo -i Same as above sudo -s Same as above su chaojun switch to another account (enter the target account password) sudo su chaojun switch to another account (enter the current account password)
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.