usermod 命令修改系统帐户文件来反映通过命令行指定的变化

1. 首先看看usermod都是有哪些参数

[root@hxweb101 ~]$ usermod --help
Usage: usermod [options] LOGINOptions:-a, --append                 append the user to the supplemental GROUPS (use only with -G) -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 -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

[ root @ hxweb101 ~ ] $ usermod -- help

Usage : usermod [ options ] LOGIN

Options :

- a , -- append                 append the user to the supplemental GROUPS

( use only with - G )

- 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

- 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

下面是网友的翻译,我直接拿来了:

-a|--append     ##把用户追加到某些组中,仅与-G选项一起使用
-c|--comment    ##修改/etc/passwd文件第五段comment
-d|--home       ##修改用户的家目录通常和-m选项一起使用
-e|--expiredate ##指定用户帐号禁用的日期,格式YY-MM-DD -f|--inactive ##用户密码过期多少天后采用就禁用该帐号,0表示密码已过期就禁用帐号,-1表示禁用此功能,默认值是-1 -g|--gid ##修改用户的gid,改组一定存在 -G|--groups ##把用户追加到某些组中,仅与-a选项一起使用 -l|--login ##修改用户的登录名称 -L|--lock ##锁定用户的密码 -m|--move-home ##修改用户的家目录通常和-d选项一起使用 -s|--shell ##修改用户的shell -u|--uid ##修改用户的uid,该uid必须唯一 -U|--unlock ##解锁用户的密码

- a | -- append      ##把用户追加到某些组中,仅与-G选项一起使用

- c | -- comment      ##修改/etc/passwd文件第五段comment

- d | -- home        ##修改用户的家目录通常和-m选项一起使用

- e | -- expiredate ##指定用户帐号禁用的日期,格式YY-MM-DD

- f | -- inactive    ##用户密码过期多少天后采用就禁用该帐号,0表示密码已过期就禁用帐号,-1表示禁用此功能,默认值是-1

- g | -- gid          ##修改用户的gid,改组一定存在

- G | -- groups      ##把用户追加到某些组中,仅与-a选项一起使用

- l | -- login        ##修改用户的登录名称

- L | -- lock        ##锁定用户的密码

- m | -- move - home    ##修改用户的家目录通常和-d选项一起使用

- s | -- shell        ##修改用户的shell

- u | -- uid          ##修改用户的uid,该uid必须唯一

- U | -- unlock      ##解锁用户的密码

实例说明:

比如我有hexu 和 www 用户和用户组:

  1. www创建为内部用户禁止远程登陆,用于运行web service。
  2. hexu创建为外部使用用户,用于登陆、调试或是上传代码等。

这时可以考虑hexu添加到www用户组,并将代码目录允许组读写:

$ usermod -a -G www hexu   # 将hexu添加到www用户组
$ chmod -R ug+w /data/code  # 将目录添加用户组可写

$ usermod - a - G www hexu    # 将hexu添加到www用户组

$ chmod - R ug + w / data / code    # 将目录添加用户组可写

下面是网友的整理,转过来了: 示例(Examples):

#1,新建用户test,密码test,另外添加usertest组
$ useradd test
$ echo "test" | passwd --stdin test
$ groupadd usertest
#2,把test用户加入usertest组 $ usermod -aG usertest test ##多个组之间用空格隔开 $ id test uid=500(test) gid=500(test) groups=500(test),501(usertest) #3,修改test用户的家目录 $ usermod -md /home/usertest $ ls /home usertest #4,修改用户名 $ usermod -l testnew(新用户名称) test(原来用户名称) $ id testnew uid=500(testnew) gid=500(test) groups=500(test),501(usertest) #5,锁定testnew的密码 $ sed -n '$p' /etc/shadow testnew:$6$1PwPVBn5$o.MIEYONzURQPvn/YqSp69kt2CIASvXhOnjv/t Z5m4NN6bJyLjCG7S6vmji/PFDfbyITdm1WmtV45CfHV5vux/:15594:0:99999:7::: $ usermod -L testnew $ sed -n '$p' /etc/shadow testnew:!$6$1PwPVBn5$o.MIEYONzURQPvn/YqSp69kt2CIASvXhOnjv/t Z5m4NN6bJyLjCG7S6vmji/PFDfbyITdm1WmtV45CfHV5vux/:15594:0:99999:7::: #6,解锁testnew的密码 $ usermod -U testnew $ sed -n '$p' /etc/shadow testnew:$6$1PwPVBn5$o.MIEYONzURQPvn/YqSp69kt2CIASvXhOnjv/t Z5m4NN6bJyLjCG7S6vmji/PFDfbyITdm1WmtV45CfHV5vux/:15594:0:99999:7::: #7,修改用户的shell $ sed '$!d' /etc/passwd testnew:x:500:500::/home/usertest:/bin/bash $ usermod -s /bin/sh testnew $ sed -n '$p' /etc/passwd testnew:x:500:500::/home/usertest:/bin/sh # 也可以手动编辑 vi /etc/passwd 找到testnew编辑保存即可 $ vi /etc/password #8,修改用户的UID $ usermod -u 578 testnew (UID必须唯一) $ id testnew uid=578(testnew) gid=500(test) groups=500(test),501(usertest) #9,修改用户的GID $ groupadd -g 578 test1 $ usermod -g 578 testnew (578组一定要存在) $ id testnew uid=578(testnew) gid=578(test1) groups=578(test1),501(usertest) #10,指定帐号过期日期 $ sed -n '$p' /etc/shadow testnew:$6$1PwPVBn5$o.MIEYONzURQPvn/YqSp69kt2CIASvXhOnjv/t Z5m4NN6bJyLjCG7S6vmji/PFDfbyITdm1WmtV45CfHV5vux/:15594:0:99999:7::: $ usermod -e 2012-09-11 testnew $ sed -n '$p' /etc/shadow testnew:$6$1PwPVBn5$o.MIEYONzURQPvn/YqSp69kt2CIASvXhOnjv/t Z5m4NN6bJyLjCG7S6vmji/PFDfbyITdm1WmtV45CfHV5vux/:15594:0:99999:7::15594: 11,指定用户帐号密码过期多少天后,禁用该帐号 $ usermod -f 0 testnew $ sed -n '$p' /etc/shadow testnew:$6$1PwPVBn5$o.MIEYONzURQPvn/YqSp69kt2CIASvXhOnjv/t Z5m4NN6bJyLjCG7S6vmji/PFDfbyITdm1WmtV45CfHV5vux/:15594:0:99999:7:0:15594:

#1,新建用户test,密码test,另外添加usertest组

$ useradd test

$ echo "test" | passwd -- stdin test

$ groupadd usertest

#2,把test用户加入usertest组

$ usermod - aG usertest test ##多个组之间用空格隔开

$ id test

uid = 500 ( test ) gid = 500 ( test ) groups = 500 ( test ) , 501 ( usertest )

#3,修改test用户的家目录

$ usermod - md / home / usertest

$ ls / home

usertest

#4,修改用户名

$ usermod - l testnew ( 新用户名称 )    test ( 原来用户名称 )

$ id testnew

uid = 500 ( testnew ) gid = 500 ( test ) groups = 500 ( test ) , 501 ( usertest )

#5,锁定testnew的密码

$ sed - n '$p' / etc / shadow

testnew : $ 6 $ 1PwPVBn5 $o .MIEYONzURQPvn / YqSp69kt2CIASvXhOnjv / t

Z5m4NN6bJyLjCG7S6vmji / PFDfbyITdm1WmtV45CfHV5vux / : 15594 : 0 : 99999 : 7 :: :

$ usermod - L testnew

$ sed - n '$p' / etc / shadow

testnew : ! $ 6 $ 1PwPVBn5 $o .MIEYONzURQPvn / YqSp69kt2CIASvXhOnjv / t

Z5m4NN6bJyLjCG7S6vmji / PFDfbyITdm1WmtV45CfHV5vux / : 15594 : 0 : 99999 : 7 :: :

#6,解锁testnew的密码

$ usermod - U testnew

$ sed - n '$p' / etc / shadow

testnew : $ 6 $ 1PwPVBn5 $o .MIEYONzURQPvn / YqSp69kt2CIASvXhOnjv / t

Z5m4NN6bJyLjCG7S6vmji / PFDfbyITdm1WmtV45CfHV5vux / : 15594 : 0 : 99999 : 7 :: :

#7,修改用户的shell

$ sed '$!d' / etc / passwd

testnew : x : 500 : 500 :: / home / usertest : / bin / bash

$ usermod - s / bin / sh testnew

$ sed - n '$p' / etc / passwd

testnew : x : 500 : 500 :: / home / usertest : / bin / sh

# 也可以手动编辑 vi /etc/passwd 找到testnew编辑保存即可

$ vi / etc / password

#8,修改用户的UID

$ usermod - u 578 testnew ( UID 必须唯一 )

$ id testnew

uid = 578 ( testnew ) gid = 500 ( test ) groups = 500 ( test ) , 501 ( usertest )

#9,修改用户的GID

$ groupadd - g 578 test1

$ usermod - g 578 testnew ( 578 组一定要存在 )

$ id testnew

uid = 578 ( testnew ) gid = 578 ( test1 ) groups = 578 ( test1 ) , 501 ( usertest )

#10,指定帐号过期日期

$ sed - n '$p' / etc / shadow

testnew : $ 6 $ 1PwPVBn5 $o .MIEYONzURQPvn / YqSp69kt2CIASvXhOnjv / t

Z5m4NN6bJyLjCG7S6vmji / PFDfbyITdm1WmtV45CfHV5vux / : 15594 : 0 : 99999 : 7 :: :

$ usermod - e 2012 - 09 - 11 testnew

$ sed - n '$p' / etc / shadow

testnew : $ 6 $ 1PwPVBn5 $o .MIEYONzURQPvn / YqSp69kt2CIASvXhOnjv / t

Z5m4NN6bJyLjCG7S6vmji / PFDfbyITdm1WmtV45CfHV5vux / : 15594 : 0 : 99999 : 7 :: 15594 :

11 , 指定用户帐号密码过期多少天后,禁用该帐号

$ usermod - f 0 testnew

$ sed - n '$p' / etc / shadow

testnew : $ 6 $ 1PwPVBn5 $o .MIEYONzURQPvn / YqSp69kt2CIASvXhOnjv / t

Z5m4NN6bJyLjCG7S6vmji / PFDfbyITdm1WmtV45CfHV5vux / : 15594 : 0 : 99999 : 7 : 0 : 15594 :

注意(caution): usermod不允许你改变正在线上的使用者帐号名称。当usermod用来改变userID,必须确认这名user没在电脑上执行任何程序

/etc/passwd user_name:x:uid:gid:commnet:home:shell

/etc/shadow username:passwd:lastchg:min:max:warn:inactive:expire:flag

  • –用户名
  • –密码
  • –从1970年1月1日起到上次修改密码所经过的天数
  • –密码再过几天可以被变更(0表示随时可以改变)
  • –密码再过几天必须被变更(99999表示永不过期)
  • –密码过期前几天提醒用户(默认为一周)
  • –密码过期几天后帐号被禁用
  • –从1970年1月1日算起,多少天后账号失效

linux usermod命令相关推荐

  1. linux的usermod命令参数,linux usermod命令参数及用法详解

    linuxusermod命令参数及用法详解,linux修改用户账号信息命令,usermod可用来修改用户帐号的各项设定.接下来是小编为大家收集的linux usermod命令参数及用法详解,欢迎大家阅 ...

  2. linux安装usermod命令,Linux usermod 命令的使用

    1.命令简介 usermod(user modify)命令是系统管理员命令,用于修改用户账号 . usermod可用来修改用户账号的各项设定,修改系统账号文件来反映通过命令行指定的变化. 2.命令格式 ...

  3. 【Linux】一步一步学Linux——usermod命令(86)

    00. 目录 文章目录 00. 目录 01. 命令概述 02. 命令格式 03. 常用选项 04. 参考示例 05. 附录 01. 命令概述 usermod命令用于修改用户账号 .usermod可用来 ...

  4. linux usermod命令修改用户属性

    usermod命令用于修改用户的基本信息.usermod命令不允许你改变正在线上的使用者帐号名称.当usermod命令用来改变user id,必须确认这名user没在电脑上执行任何程序.你需手动更改使 ...

  5. linux usermod用法 -l,linux usermod命令参数及用法详解(linux修改用户账号信息命令

    原文http://www.51itstudy.com/31332.html 命 令:usermod 功能说明:修改用户帐号. 语 法:usermod [-LU][-c ][-d ][-e ][-f ] ...

  6. Linux命令篇之usermod命令和passwd命令

    usermod命令参数及用法详解(linux修改用户账号信息命令) linux usermod命令参数及用法详解,linux修改用户账号信息命令,usermod可用来修改用户帐号的各项设定 命 令:u ...

  7. Linux 命令(131)—— usermod 命令

    1.命令简介 usermod(user modify)命令是系统管理员命令,用于修改用户账号 . usermod可用来修改用户账号的各项设定,修改系统账号文件来反映通过命令行指定的变化. 2.命令格式 ...

  8. Linux命令 - usermod命令

    Linux命令 - usermod命令   Linux usermod 命令用于修改用户帐号. 1.语法: usermod [选项] [用户名] 2.功能:   可用来修改用户帐号的各项设定. 3.参 ...

  9. linux usermod用法,Linux中的usermod命令的详细解释

    在Linux系统中,usermod命令的主要功能是修改用户账户,下面由学习啦小编为大家整理了linux下的usermod命令的详细解释,希望对大家有帮助! Linux中的usermod命令的详细解释 ...

最新文章

  1. python 自己写个调试工具
  2. flutter 主题切换
  3. 在Mapnik中显示中文(网上资料整理)
  4. [转]进程,线程和多线程
  5. 【报错笔记】在eclipse中复制代码后代码中会报画红线错,而且项目也会报错。
  6. finalizer_Java Finalizer和Java文件输入/输出流
  7. vs显示堆栈数据分析_什么是“数据分析堆栈”?
  8. python怎么开发工具_为程序员和新手准备的8大Python开发工具
  9. 哈佛学生是如何度过大学4年的(没有学习动力时候就看一遍)
  10. redo mysql mvcc_Mysql事务中的ACID是怎么实现的
  11. ----发现一款可以代替双手的软件 “按键精灵”
  12. vue+html5实现分类、商品分类、类别、菜单的左右层级布局两种不同精美样式
  13. 论文笔记:ARTNet、Non-local Neural Networks
  14. (素材源码)swanzhu学IOS(三)打飞机
  15. 人月神话(七)没有银弹-软件工程中的根本和次要问题、20 年后的人月神话
  16. Linux中的虚拟机图形界面安装步骤,批量完成虚拟机硬件配置
  17. Linux管道命令及管道相关命令(详细)
  18. 599. 两个列表的最小索引总和
  19. 2021计通网项目一问题记录
  20. 小试Python中的pack()方法

热门文章

  1. 对于web安全测试的一些感悟
  2. 监听屏幕滚动开始和结束事件(scroll start 和scroll stop)
  3. Python编程基础:实验5——函数定义与调用
  4. Unity 游戏框架搭建 2018 (四) 我所理解的框架
  5. JavaScript二维数组与函数
  6. java servlet init_Java ServletRegistration.setInitParameters方法代码示例
  7. docker inspect 详解
  8. 企业搬迁 四通搬家再为市场树立行业新标准
  9. 天秤女天蝎男的缘与份
  10. 中国元宇宙+星云虚境