1. 创建testuser uid 1234,主组:bin,辅助组:root,ftp,shell:/bin/csh home:/testdir/testuse

-c, --comment COMMENT 添加用户全名或注释

-u, --uid UID 指定uid

-g, --gid GROUP 指定主组

-G, --groups GROUP1[,GROUP2,...[,GROUPN]]] 指定附加组

-d, --home-dir HOME_DIR 指定家目录

-s, --shell SHELL 指定默认shell

      主要是熟悉useradd的常用选项,-d指定目录的时候,要先确定其父目录存在

    现有一testuser用户,进行修改


[root@localhost ~]# usermod -u 1234 -g bin -G root,ftp -s /bin/csh -d /testdir/testuser testuser


查询结果:


[root@localhost ~]# id testuser







2. 修改testuser uid:4321,主组:root,辅助组:nobody,loginname:test,home:/home/test 家数据迁移

-u, --uid UID 指定uid

-g, --gid GROUP 指定主组

-G, --groups GROUP1[,GROUP2,...[,GROUPN]]] 指定辅助组

-l, --login NEW_LOGIN 指定新的登陆名

-d, --home HOME_DIR 指定家目录

-m, --move-home 移动家目录,一般要与-d使用

主要是熟悉usermod的常用选项


[root@localhost ~]# usermod -u 4321 -g root -G nobody -l  test -md /home/test testuser


查询结果:

[root@localhost ~]# id testuser

                                   无此用户


[root@localhost ~]# id test




3. 批量创建帐号:user1...user10

uid:3000-3009,shell:/bin/csh,home:/testdir/username

passwd:usernamepass

注意家目录相关配置,使用户正常登录

主要掌握newusers和chpasswd两个命令,还要确认系统是存在/bin/csh

newusers命令批量创建用户,注意文件与/etc/passwd相同,我们可以查看newusers的man手册:


首先创建一个user.txt文件

[root@localhost ~]# vi user.txt

在文件内编辑要创建的用户:

[root@localhost ~]# vi user.txt

[root@localhost ~]# cat user.txt

user1:user1pass:3000:3000::/testdir/username1:/bin/csh

user2:user2pass:3001:3001::/testdir/username2:/bin/csh

user3:user3pass:3002:3002::/testdir/username3:/bin/csh

user4:user4pass:3003:3003::/testdir/username4:/bin/csh

user5:user5pass:3004:3004::/testdir/username5:/bin/csh

user6:user6pass:3005:3005::/testdir/username6:/bin/csh

user7:user7pass:3006:3006::/testdir/username7:/bin/csh

user8:user8pass:3007:3007::/testdir/username8:/bin/csh

user9:user9pass:3008:3008::/testdir/username9:/bin/csh

user10:user10pass:3009:3009::/testdir/username10:/bin/csh

 

使用newusers命令批量创建用户:

user5:user5pass:3004:3004::/testdir/username5:/bin/csh

user6:user6pass:3005:3005::/testdir/username6:/bin/csh

user7:user7pass:3006:3006::/testdir/username7:/bin/csh

user8:user8pass:3007:3007::/testdir/username8:/bin/csh

user9:user9pass:3008:3008::/testdir/username9:/bin/csh

user10:user10pass:3009:3009::/testdir/username10:/bin/csh

[root@localhost ~]# newusers user.txt

[root@localhost ~]# cat /etc/passwd

root:x:0:0:root:/root:/bin/bash

bin:x:1:1:bin:/bin:/sbin/nologin


查看/etc/passwd下的用户信息

[root@localhost ~]# cat /etc/passwd


user1:x:3000:3000::/testdir/username1:/bin/csh

user2:x:3001:3001::/testdir/username2:/bin/csh

user3:x:3002:3002::/testdir/username3:/bin/csh

user4:x:3003:3003::/testdir/username4:/bin/csh

user5:x:3004:3004::/testdir/username5:/bin/csh

user6:x:3005:3005::/testdir/username6:/bin/csh

user7:x:3006:3006::/testdir/username7:/bin/csh

user8:x:3007:3007::/testdir/username8:/bin/csh

user9:x:3008:3008::/testdir/username9:/bin/csh

user10:x:3009:3009::/testdir/username10:/bin/csh



切换账号,用新建账户登录:

Last login: Tue Aug  2 22:58:51 2016

/usr/bin/xauth:  file /testdir/username1/.Xauthority does not exist

[user1@localhost ~]$ su user2

密码:

[user2@localhost username1]$