Common commands for Linux user and group management

Source: Internet
Author: User
Tags echo command


1. List the usernames of all logged-on users on the current system. Note: Only one user can be logged on multiple times.

~] # Who | cut-d ""-f1 | sort-u

2. Retrieve the information about the user logging on to the current system.

~] # Last-x | head-1

3. Retrieve the shell on the current system that is most used as the default shell.

~] # Cut/etc/passwd-d ":"-f7 | uniq-c sort-n tail-1

4. Change the information of the last 10 users with the maximum value of the Third Field in/etc/passwd to uppercase and save the information to the/tmp/maxusers.txt file.

~] # Sort-t ":"-k3-n/etc/passwd | tail-10 tr [[: lower:] [[: upper:]>/tmp/maxuser.txt

5. Retrieve the IP address of the current host. The prompt is: split the result of the ifconfig command.

~] # Ifconfig | grep 'inet '| grep-v '2017. 0.0.1' | cut-d:-f2 | awk '{print $2 }'

6. List all file names ending with. conf in the/etc directory, convert the names to uppercase, and save them to the/tmp/etc. conf file.

~] # Ls-a/etc | egrep *. conf $ | tr [[: lower:] [[: upper:]>/tmp/etc. conf

7. Display the total number of subdirectories or files under the/var directory.

~] # Find/var-type f wc-l

8. Retrieve the names of the 10 groups with the minimum value of the third field in the/etc/group file.

~] # Sort-t ":"-k3/etc/group | head-10 | cut-d ":"-f1

9. Merge the/etc/fstab and/etc/issue files into the same content and save it to the/tmp/etc. test file.

~] # Cat/etc/{fstab, issue}> tmp/etc. test

10. Summarize the usage of user and group management commands and complete the following exercises:

(1) create a distro group with a GID of 2016;

~] # Groupadd distro-g 2016

~] # Cat/etc/group | grep distro

(2) create a user named "mandriva", whose ID number is 1005, and the BASIC group is "distro;

~] # Useradd-u 1005-g 2016 mandriva

~] # Cat/etc/passwd | grep mandriva

Mandriva: x: 1100: 2016:/home/mandriva:/bin/bash

(3) create the mageia user. The ID number is 1100, and the home directory is/home/linux;

~] # Useradd-u 1100-d/home/linux mageia

~ [Root @ localhost tmp] # cat/etc/passwd | grep mageia

Mageia: x: 1100: 1100:/home/linux:/bin/bas

(4) add a password for mageia to the user. The password is mageedu;

~] # Passwd mageia

Changing password for user mageia.

New password:

Bad password: The password is shorter than 8 characters

Retype new password:

Passwd: all authentication tokens updated successfully.

(5) delete mandriva, but keep its home directory;

~] # Userdel mandriva

(6) create the slackware user. The ID number is 2002, the BASIC group is distro, and the additional group is peguin;

~] # Groupadd peguin

~] # Useradd-u 2002-g distro-G peguin slackware

~] # Cat/etc/passwd | grep slackware

Slackware: x: 2002: 2016:/home/slackware:/bin/bash

~] # Id slackware

Uid = 2002 (slackware) gid = 2016 (distro) group = 2016 (distro), 2017 (peguin)

(7) modify slackware's default shell to/bin/tcsh;

~] # Usermod-s/bin/tcsh slackware

~] # Cat/etc/passwd | grep slackware

Slackware: x: 2002: 2016:/home/slackware:/bin/tcsh

(8) add an additional group admins for slackware;

~] # Usermod-aG admins slackware

~] # Id slackware

Uid = 2002 (slackware) gid = 2016 (distro) group = 2016 (distro), 2017 (peguin), 2018 (admins)

(9) add a password for slackware. The minimum password validity period is 3 days, the maximum password is 180 days, and the warning is 3 days;

~] # Passwd slackware

Changing password for user slackware.

New password:

Bad password: The password fails the dictionary check-it is too simplistic/systematic

Retype new password:

Passwd: all authentication tokens updated successfully.

~] # Passwd-n 3-x 180-w 3 slackware

Adjusting aging data for user slackware.

Passwd: Success

~] # Cat/etc/shadow | grep slackware

Slackware: $6 $ gk2px/TP

$ Response.: 17056: 3: 180: 3 :::

(10) add an openstack user. The ID number is 3003, the BASIC group is clouds, and the additional groups are peguin and nova;

~] # Groupadd clouds

~] # Groupadd nova

~] # Useradd-u 3003-g clouds-G peguin, nova openstack

~] # Id openstack

Uid = 3003 (openstack) gid = 2019 (clouds) group = 2019 (clouds), 2017 (peguin), 2020 (nova)

(11) add the system user mysql and require the shell to be/sbin/nologin;

~] # Useradd-r-s/sbin/nologin mysql

~] # Cat/etc/passwd | grep mysql

Mysql: x: 988: 983:/home/mysql:/sbin/nologin

(12) use the echo command to add a password for openstack in non-interactive mode.

~] # Echo "12345678" | passwd-stdin openstack

Changing password for user openstack.

Passwd: all authentication tokens updated successfully.

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.