Keep on going, never give up.

Linux下创建删除用户(组)

LINUX创建和删除用户非常简单,假设创建一个tstusr用户,所属用户组为tstgroup。创建和删除用户需要root权限,所以如果非root登录,请尝试使用sudo命令。

一、查看用户和组

查看用户和组,只需查看/etc/passwd文件即可。

几个常用用户管理命令:

  • useradd 添加用户
  • adduser 添加用户
  • passwd 为用户设置密码
  • usermod 修改用户命令,可以通过usermod 来修改登录名、用户的家目录等等;
  • id 查看用户的UID、GID及所归属的用户组
  • chfn 更改用户信息工具
  • su 用户切换工具

几个常用管理用户组命令;

  • groupadd 添加用户组;
  • groupdel 删除用户组;
  • groupmod 修改用户组信息
  • groups 显示用户所属的用户组

二、创建用户组

添加用户组命令如下:

groupadd tstgroup

上一句添加一个tstgroup用户组。 

三、创建Linux新用户

命令如下:

useradd -g tstgroup -d /home/tstusr -s /etc/bash -m tstusr

语法格式:

useradd -g 所属组 -d 家目录 -s 所用的SHELL

If you want to add a bash user(cmdusr in bashgrp), just like this:

groupadd bashgrp

useradd -r -s /bin/bash -g bashgrp cmdusr

Refer to the notes for more information.

四、删除Linux用户

删除用户命令如下:

userdel -r tstusr

或,下面两句:

userdel tstusr

rm -rf /home/tstusr

上一句是删除用户帐号,下面一句是删除用户家文件夹。

Notes:

1. Usage: useradd [options] LOGIN

Options:
-b, --base-dir BASE_DIR base directory for the home directory of the new account
-c, --comment COMMENT GECOS field of the new account
-d, --home-dir HOME_DIR home directory of the new account
-D, --defaults print or change default useradd configuration
-e, --expiredate EXPIRE_DATE expiration date of the new account
-f, --inactive INACTIVE password inactivity period of the new account
-g, --gid GROUP name or ID of the primary group of the new account
-G, --groups GROUPS list of supplementary groups of the new account
-h, --help display this help message and exit
-k, --skel SKEL_DIR use this alternative skeleton directory
-K, --key KEY=VALUE override /etc/login.defs defaults
-l, --no-log-init do not add the user to the lastlog and faillog databases
-m, --create-home create the user's home directory
-M, --no-create-home do not create the user's home directory
-N, --no-user-group do not create a group with the same name as the user
-o, --non-unique allow to create users with duplicate (non-unique) UID
-p, --password PASSWORD encrypted password of the new account
-r, --system create a system account
-s, --shell SHELL login shell of the new account
-u, --uid UID user ID of the new account
-U, --user-group create a group with the same name as the user
-Z, --selinux-user SEUSER use a specific SEUSER for the SELinux user mapping

 

2. Usage: usermod [options] LOGIN

Options:
-c, --comment COMMENT new value of the GECOS field
-d, --home HOME_DIR new home directory for the user account
-e, --expiredate EXPIRE_DATE set account expiration date to EXPIRE_DATE
-f, --inactive INACTIVE set password inactive after expiration to INACTIVE
-g, --gid GROUP force use GROUP as new primary group
-G, --groups GROUPS new list of supplementary GROUPS
-a, --append append the user to the supplemental GROUPS mentioned by the -G option without removing
him/her from other groups
-h, --help display this help message and exit
-l, --login NEW_LOGIN new value of the login name
-L, --lock lock the user account
-m, --move-home move contents of the home directory to the new location (use only with -d)
-o, --non-unique allow using duplicate (non-unique) UID
-p, --password PASSWORD use encrypted password for the new password
-s, --shell SHELL new login shell for the user account
-u, --uid UID new UID for the user account
-U, --unlock unlock the user account
-Z, --selinux-user new SELinux user mapping for the user account
 

参考资料:

http://weiruoyu.blog.51cto.com/951650/769641

http://baike.baidu.com/view/3907948.htm

相关评论(0):  

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

订阅博客

最新文章

本站采用创作共用版权协议, 要求署名、非商业用途和保持一致. 转载也必须遵循“署名-非商业用途-保持一致”的创作共用协议. 返回顶部
Copyright@2005-2016 Metsky.com, All rights Reserved.