Linux (V)-Common commands for user management

Source: Internet
Author: User

Linux (v) ---- You can directly submit a requirement to manage user group permissions for Common commands! The steps are completed first and then analyzed later. Authorized users chongshi and bugmaster have the write permission to create the directory www.2cto.com [root @ localhost hzh] # mkdir/cnblogs create directory [root @ bogon hzh] # ls-ld/cnblogs View directory drwxr-xr-x 2 root 4096 May 10 23:20/cnblogs add two users and set the password [root @ bogon hzh] # useradd chongshi create user [root @ bogon hzh] # passwd chongshi set the password Changing password for user chongshi. new UNIX password: bad password: it is based on a dictionary wordRetype new UNIX password: p Asswd: all authentication tokens updated successfully. [root @ bogon hzh] # useradd bugmaster [root @ bogon hzh] # passwd bugmasterChanging password for user bugmaster. new UNIX password: bad password: it is based on a dictionary wordRetype new UNIX password: www.2cto.com passwd: all authentication tokens updated successfully. add a group [root @ bogon hzh] # groupadd testing create a group [root @ bogon hzh] # grep testing/etc/gr Oup to view the group information testing: x: 506: add User to group [root @ bogon hzh] # usermod-G testing chongshi user chongshi add to group testing [root @ bogon hzh] # gpasswd-a bugmaster testing user bugmaster add to group group testingAdding user bugmaster to group testing note: the above two methods are different, but the functions are the same. Users are added to the group. [Root @ bogon hzh] # grep testing/etc/group check the members testing: x: 506: chongshi in the group. We know what permissions the group has, what permissions does a group member have. Set the group of the cnblogs directory to testing [root @ bogon hzh] # change the group of the/cnblogs directory to testing [root @ bogon hzh] # ls-ld/cnblogs view the directory group drwxr-xr-x 2 root testing 4096 May 10 23:20/cnblogs add write permission to the group [root @ bogon hzh] # chmod g + w/cnblogs add write permission to the group [root @ bogon hzh] # ls-ld/cnblogs view the directory permission of the group. drwxrwxr-x 2 root testing 4096 23:20/cnblogs. Now the chongshi and bugmaster users have the write permission on/cnbogs. [root @ bogon hzh] # su -- chongshi switch user [c Hongshi @ bogon hzh] $ touch/cnblogs/abc: create a file. (If a file is successfully created under the directory, you have the write permission on the directory) it is a little complicated to add a user using common operation commands. Let's take a look at the options root @ fnngj-virtual-machine: /# useradd-DGROUP = 100 www.2cto.com HOME =/homeINACTIVE =-1 EXPIRE = SHELL =/bin/shSKEL =/etc/skelCREATE_MAIL_SPOOL = no parameter description:-u: UID-g: the Default User Group GID-G: Specifies the group to which it belongs-d: directory-s: Command Interpreter Shell-c: Description-e: Specifies the user expiration time example: root @ fnngj-virtual-machine:/# useradd-u 1888-g webadmin-G sys, root-s /Bin/bash-c "market lisi"-e 2012-12-12 jack adds the user to the group usermod-G [group name] [user name] root @ fnngj-virtual-machine: /# usermod-G webadmin tomroot @ fnngj-virtual-machine:/# grep webadmin/etc/groupwebadmin: x: 1001: tom modified username usermod-l [new username] [old username] the content of the modified User is basically the same as that of the added user, but there is an additional option to modify the user. Root @ fnngj-virtual-machine:/# usermod-l tom jack changed jack to tom to delete user userdel-r [user name]-r: delete user group manually delete: use the find command to find the find option-user,-uid,-group,-gid, 1. Move and back up the files to be retained. delete the required file 3. Clear related table items in the user File 4. Clear the user's home directory [root @ bogon/] # find/home-user fnngj/home/fnngj www.2cto.com/home /fnngj /. bashrc/home/fnngj /. bash_profile/home/fnngj /. gtkrc/home/fnngj /. bash_history/home/fnngj /. bash_logout can be used to identify the desired user information. User information check Command pwck detection/etc/passwd file check whether the user's setting file is normal. Enter the command directly, and edit the/etc/passwd file without The vipw parameter. The biggest difference between the command and vi is to lock the file during editing. If multiple users have the editing permission on the passwd file, it will cause confusion if multiple users edit the file at the same time. When you use vipw to edit a passwd file, others cannot open the passwd file. Id to view the user id and group information. Enter the command directly without the [root @ bogon fnngj] # iduid = 0 (root) gid = 0 (root) groups = 0 (root), 1 (bin), 2 (daemon), 3 (sys), 4 (adm), 6 (disk), 10 (wheel) context = root: system_r: unconfined_t finger: view the logon information of the current user. finger [user name]: view the details of a user. [Root @ bogon fnngj] # fingerLogin Name Tty Idle Login Time Office Phoneroot root pts/1 May 13 (192.168.203.1) [root @ bogon fnngj] # finger rootLogin: root Name: root www.2cto.com Directory:/root Shell:/bin/bashOn since, December 31, May 13 14:57 (CST) on pts/1 from 192.168.203.1New mail received ed, December 31, May 6 11:00 2012 (CST) unread since March 3 20:40 2012 (CST) No Plan. su [user name] switch user (su-environment variable switch) su-[user name] Switch The environment variable [root @ bogon/] # su fnngj [fnngj @ bogon/] $ echo $ PATH/usr/kerberos/sbin: /usr/kerberos/bin:/usr/local/bin:/usr/X11R6/bin: /home/fnngj/bin [fnngj @ bogon/] $ su rootPassword: [root @ bogon/] # su-fnngj [fnngj @ bogon ~] $ Echo $ PATH/usr/kerberos/bin:/usr/local/bin:/usr/X11R6/bin: /home/fnngj/bin passwd-S [user name] view User Password status [root @ bogon fnngj] # passwd-S fnngjPassword set, MD5 crypt. who and w view the current Login User information [fnngj @ bogon ~] $ Whoroot pts/1 May 13 (192.168.203.1) [fnngj @ bogon ~] $ W15: 11: 29 up 54 min, 1 user, load average: 0.00, 0.00, 0.00 user tty from login @ idle jcpu pcpu WHATroot pts/1 192.168.203.1 57 0.00 s 0.84 s 0.01 s users disable and resume disabled and restored users when a USER is operating normally in violation of regulations this operation is not required in the near future, we can lock this user. Just as if your game account is disabled due to an exception. Forbidden disabled # usermod-L username # passwd-l username restored www.2cto.com # usermod-U username # passwd-u username disabled [root @ bogon/] # passwd-l fnngj disabled fnngj user Locking password for user fnngj. passwd: Success [root @ bogon/] # passwd-S fnngjPassword locked. prompt to be disabled [root @ bogon/] # passwd-u fnngj password to unlock Unlocking password for user fnngj. passwd: Success. [root @ B Ogon/] # passwd-S fnngjPassword set, MD5 crypt. how to disable it: [root @ bogon/] # grep fnngj/etc/shadowfnngj: $1 $ EudBseaZ $ kw1s8zs2dsvnj83phhv1_0: 15456: 0: 99999: 7 ::: [root @ bogon/] # passwd-l fnngjLocking password for user fnngj. passwd: Success [root @ bogon/] # grep fnngj/etc/shadowfnngj :!! $1 $ EudBseaZ $ kw1s8zs2dsvnj83phhv1_0: 15456: 0: 99999: 7 ::: you can see the operation above. After I disable your password, the password still exists in the shadwo file, but there are two more exclamation points (!) in front of it (!!), In this way, you cannot log on, because the verification terminal has changed the password. Of course, after unlocking, the Two exclamation points in front of the password will be removed. As a matter of fact, we can disable users by editing files through vi without using commands. Common User Group operation commands first look at what content is stored in the group configuration file [root @ bogon/] # more/etc/grouproot: x: 0: root www.2cto.com bin: x: 1: root, bin, daemondaemon: x: 2: root, bin, daemonsys: x: 3: root, bin, admadm: x: 4: root, adm, daemontty: x: 5: disk: x: 6: rootlp: x: 7: daemon, lpmem: x: 8: kmem: x: 9: wheel: x: 10: rootmail: x: 12: mailnews: x: 13: newsuucp: x: 14: uucpman: x: 15: games: x: 20: gopher: x: 30 :................. dialout: x: 20: fnngjdialout Add User Group groupadd [user group name] root @ fnngj-virtual-machine: /# groupadd webadmin Add a group webadminroot @ fnngj-virtual-machine:/# grep webadmin/etc/group view group information webadmin: x: 1001: when adding a group, you can also specify the group's idroot @ fnngj-virtual-machine:/# groupadd-g 8888 webadminroot @ fnngj-virtual-machine: /# grep webadmin/etc/group webadmin: x: 8888: www.2cto.com delete user group: groupdel [user group name] [root @ bogon/] # groupdel webadmin Delete group we Badmin modify user group information groupmod-n [new group name] [old group name] [root @ bogon/] # groupmod-n apache webadmin modify group name webadmin to apache user group information view command groups View user Group [root @ bogon/] # groups fnngjfnngj: fnngjnewgrp switching user group [root @ bogon/] # newgrp fnngj is not a member of the group. If you know the group password (if you have a password), you can switch between them. The grpck user group configuration file detects that the chgrp modification file belongs to the group vigr editing/etc/group file (locked file). Similar to vipw, other users are prohibited from editing the group file. Prevent write operations by multiple users, resulting in write confusion. The user group management command gpasswd command is a command available in all linux systems. Let's take a look at all the parameters. Root @ fnngj-virtual-machine:/# gpasswdUsage: gpasswd [option] GROUPOptions: www.2cto.com-a, -- add USER to GROUP-d, -- delete USER remove USER from GROUP-h, -- help display this help message and exit-r, -- remove-password remove the GROUP's password-R, -- restrict access to GROUP to its members-M, -- members USER ,... set the list of members of GROUP-A, -- administrators ADMIN ,... s Et the list of administrators for groupshould t for the-A and-M options, the options cannot be combined. Although the above parameter information is in English, it is not explained. I believe you know it. Simple usage: root @ fnngj-virtual-machine:/# gpasswd-a tom webadmin add users to the group root @ fnngj-virtual-machine: /# gpasswd-d tom webadmin deletes the user from the group root @ fnngj-virtual-machine:/# gpasswd webadmin sets the user group password root @ fnngj-virtual-machine: /# gpasswd-A tom webadmin promote tom to the group administrator root @ fnngj-virtual-machine:/# gpasswd-r webadmin Delete group password root @ fnngj-virtual-machine: /# gpasswd-R webadmin prohibits other users from switching to the group author's insect master

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.