Linux修改用户基本信息

(1).usermod修改用户基本信息

usermod [选项] 登录名

1)常用选项

-d,--home HOME_DIR    用户的新主目录
-g,--gid GROUP    强制GROUP为新主组
-G,--group GROUPS    新的附加组列表GROUPS(去除原有附加组)
-L,--lock    锁定用户账户
-m,--move-home  将主目录位置移至新位置(仅与-d一起使用) -s,--shell SHELL 该用户账户的新登录shell -u,uid UID  用户账户的新UID -U,--unlock 解锁用户账户

2)实例

修改UID

[root@xuexi ~]# useradd t1
[root@xuexi ~]# id t1
uid=1001(t1) gid=1001(t1) 组=1001(t1)
[root@xuexi ~]# usermod -u 1111 t1
[root@xuexi ~]# id t1
uid=1111(t1) gid=1001(t1) 组=1001(t1)

修改登录shell

[root@xuexi ~]# grep t1 /etc/passwd
t1:x:1111:1001::/home/t1:/bin/bash
[root@xuexi ~]# usermod -s /sbin/nologin t1
[root@xuexi ~]# grep t1 /etc/passwd
t1:x:1111:1001::/home/t1:/sbin/nologin

修改主目录,-m -d选项

[root@xuexi ~]# ls /home/
t1  xf
[root@xuexi ~]# usermod -m -d /opt/t1 t1
[root@xuexi ~]# ls /home/
xf
[root@xuexi ~]# ls /opt/
rh  t1

修改说明信息

[root@xuexi ~]# grep t1 /etc/passwd
t1:x:1111:1001::/opt/t1:/sbin/nologin
[root@xuexi ~]# usermod -c "hello world" t1
[root@xuexi ~]# grep t1 /etc/passwd
t1:x:1111:1001:hello world:/opt/t1:/sbin/nologin

(2).直接修改配置文件

vim /etc/passwd

 格式如下:

用户名:密码占位符:UID:GID:用户描述:用户主目录(即~):登录后的shell

猜你喜欢

转载自www.cnblogs.com/diantong/p/10232769.html