RedHat learn linux user management commands (add, delete, modify)

Source: Internet
Author: User
Tags pkill

Force kicker Login User in Linux

View users logged on to the machine

[Root @ sunsyk ~] # W

16:29:02 up 2 days, 5 Users, load average: 0.03, 0.05, 0.01

User tty from login @ idle jcpu pcpu what

Root pts/1: 0.0 tue15 2 days 0.04 s-Bash

Root pts/2: 0.0 tue15 46: 42 m 0.05 s 0.05 s bash

Root pts/3: 0.0 tue15 2 days 0.02 s 0.02 s bash

Root pts/4 172.20.52.114 58: 48 0.16 s 0.03 s sqlplus

Root pts/5 172.20.52.114 0.00 s 0.03 s w

I kicked out pts/1 (only the root user can kill the user)

[Root @ sunsyk ~] # Pkill-kill-T pts/1

[Root @ sunsyk ~] # Pkill-kill-T pts/2

[Root @ sunsyk ~] # Pkill-kill-T pts/3

Check whether it is kicked out.

[Root @ sunsyk ~] # W

16:34:16 up 2 days, 2 users, load average: 0.00, 0.05, 0.02

User tty from login @ idle jcpu pcpu what

Root pts/4 172.20.52.114 1: 04 m 0.16 s 0.03 s sqlplus

Root pts/5 172.20.52.114 0.00 s 0.03 s w

 

Log On with the LOGIN command:

In addition to the "Su-" command, you can also use the "login" command to change your identity or even log on to other hosts. If you use the "login" command to change your identity, you only need to enter the username you want to change after the command: [root @ NS1 root] # login Caroline-> change the username to Caroline, to log on to another host, use the "-h" parameter in combination with the "login" command: [root @ NS1 root] # login-H linux2-> host with the login name linux2.

Log On with the rlogin command:

In addition to the "login" command, "rlogin" can also be used to log on to a remote host. Its usage is simple. The following is an example of connecting to linux2.jschuse.com:

[Root @ NS1 root] # rlogin linux2.jschuse.com-> log on to linux2.jschuse.com

Password: ******-> by default, login is logged in with the same name, so no "login" information is displayed.

Login incorrect-> If the name used for logon is different from the current user name, press enter directly and ignore the error message.

Login: Jack-> re-enter different user names

Password: *****-> Password

Use of the/etc/nologin file:

If you want only the root user to log on to the host, but other accounts cannot log on, you can add a file named "nologin" under the/etc directory. In this file, you only need to enter a few characters at will, as long as the system finds that the file exists, other users are prohibited from logging on to the file.

System logout:

The preceding section describes how to use the "login" command to change the identity and even log on to other hosts. The "logout" command opposite to login allows currently logged on users to log out of the system, so that other users can log on. This command is easy to use. You only need to enter "logout" to log on to the system: [root @ NS1 root] # logout

As mentioned earlier, Linux is a multi-user operating system, and the permission of each user in the system must be set by the system administrator. This section describes some system administrator commands for managing users and user groups.

4.6.1 create a new user

The useradd command (you can also use adduser) to create a user account. The command format is as follows:

Table 4-19 common options of the useradd command

Common Phenomena

Yi

-D

Set the login directory for new users

-E

Set the end date of the new user. The date format is mm/DD/yy.

-F

The account will be permanently suspended several days after it expires. When the value is 0, the account is immediately suspended. If the value is-1, this function is disabled. The default value is-1.

-G

Add new users to a group

-G

Add new users to a new group. Each group is separated by commas (,) and cannot contain blank characters.

-S

Specify the login shell of a new user

-U

Set the ID of a new user

After a new user is created, the user information will be added to the/etc/passwd file in the following format:

[User name]: [Password]: [uid]: [GID]: [identity description]: [main directory]: [Login Shell 〕

The fields are divided into seven parts by the colon.

Because the UID and GID smaller than 500 are generally reserved by the system and do not need to be used as a sign for common users and groups, the newly added users and groups are generally UID and GID greater than 500.

For example, run the following command:

[Root @ localhost root] # useradd user1

A user named userl will be created, which has been introduced about user management commands and will not be described here.

The result of executing the useradd command is 11-13.

 

4.6.2 set and modify the User Password passwd

The passwd command is used to set and modify user commands. Only super users and users can change their own passwords. Other common users do not have the right to change the passwords of other users. The command is as follows:

# Passwd (user name 〕

To avoid being noticed when you enter a password, Linux does not use a password similar to Windows to echo the password (displayed as *). Therefore, these characters cannot be entered. For example, you can use the following command to set a password for the newly created userl User:

[Root @ localhost root] # passwd user1

Enter the password twice according to the system prompt. The system will display the following:

Passwd: All authentication tokens updated successfully

Indicates that the password is successfully modified. The creation of a user is only completed after the user has set a password. Otherwise, the user cannot log on with the user name.

 

4.6.3 modify user information usermod

The usermod command is used to modify user information. The command format is as follows:

# Usermod [Options] [user name 〕

The commonly used Command Options are 11-20.

Table 4-20 common options of The usermod command

Common options

Yi

-D

Update the user's new logon directory

-E

Set the end date of the new user. The date format is mm/DD/yy.

-F

The account will be permanently suspended several days after it expires. When the value is 0, the account is immediately suspended. If the value is-1, this function is disabled. The default value is-1.

-G

Update new user to join Group

-G

Define the user as a group member. Each group uses "?" Separated, cannot contain blank characters

-L

Change the name of the user during login, and the user directory name will be changed to a new name.

-S

Specify New User Shell

-U

User ID value, which must be a unique ID value. The USERID of the document directory used under the user directory will be automatically changed. Manually change the document directory that is placed outside the support directory.

For example, the following command modifies user information:

[Root @ localhost root] # usermod-D/home/user2-S/bin/bash user2

Set the main directory path of user2 to/home/user1 and the shell to/usr/bin/GCC.

Generally, The usermod command modifies the user account information by referring to the command instructions. However, usermod does not allow you to change the name of an online user account. Therefore, when you use usermod to change the user account information, you must confirm that this user account did not execute any program on the computer.

4.6.4 create a group groupadd

The groupadd command is used to create a new user group. The command format is as follows:

# Groupadd [Option] [user name 〕

Common options include:

-G: GID value. Unless the-O parameter is used, the value must be unique and cannot be the same. The value cannot be negative.

By default, the GID value is increased at least 500. Traditionally, 0-499 is reserved for system accounts.

-F: an existing group account is added. The system displays an error message and ends groupadd.

In this case, the Group will not be added (in this case, the system will not be added once ). You can also add the-G option. When you add a GID, the GID does not need to be a unique value. You do not need to add the-O parameter, the created group displays the created result (adding a group as neither-G or-O options were specified). This is an additional option added to Red Hat Linux.

4.6.5 delete user userdel

The userdel command is used to delete existing users and related documents. The command format is as follows:

# Userdel [Option] User Name

Common options for The userdel command:

-R: Delete the documents in the user directory. Documents from other locations will also be found and deleted one by one.

Userdel is not allowed to remove online user accounts. Therefore, to delete such user accounts, you must first kill the programs running on the system before deleting the accounts.

4.6.6 delete a group groupdel

The groupdel command is used to delete an existing user group. The command format is as follows:

# Groupdel group name

Similar to userdel, if a user in any group is online, the user group cannot be removed. Therefore, if a user in the group is online, it is best to remove the user first, delete the user.

 

4.6.7 switch su between users

The su command is often used for switching between different users. The command format is as follows:

# Su [user name 〕

The common usage of the su command is to change to a user or a Super User. If a su command without a user name is issued, the system prompts you to enter the root password. after entering the root password, you can change it to the root user. If you log on as the root user, you can use the su command to become any user on the system without a password.

For example, to switch to user2 if user1 is logged in, use the following command:

# Su user2

Then the system prompts you to enter the user2 password. after entering the correct password, you can switch to user2. After that, you can use the exit command to return to user1.

 

4.6.8 view the current online user who

The WHO command is used to view the current online users. This command is very useful. If you want to establish communication with other users, such as using the talk command, you must first make sure that the user is online. Otherwise, the talk process cannot be established.

Another example is that the system administrator also needs to use the who command to monitor what each login user is doing at this moment. Common command formats and options for who commands are as follows:

# Who [Option 〕

Table 4-21 lists the common command options for the command who.

Table 4-21 WHO Common commands

Common options

Yi

-

Show all information of all users

-M

Displays the user name for running the program, which is the same as "Who am I ".

-Q

Only the user's login account and number of login users are displayed. This option has a higher priority than any other options.

-U

The last time the user performed the system operation is displayed after the login user.

-H

Show Column Title

 

All options are optional. For example, run the following command:

[Root @ localhose root] # Who-ah

Address: http://www.cnblogs.com/guangbei/archive/2010/04/26/1721163.html

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.