练习题;

1、创建用户gentoo,附加组为bin和root,默认shell为 /bin/csh,注释信息为"Gentoo Distribution"

2、创建testuser uid 1234,主组:bin,辅助组:root,ftp,shell:/bin/csh home:/testdir/testuser

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

4、批量创建帐号:user1...user10

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

passwd:usernamepass

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

答案;

1、

[root@centous1 home]# useradd -c 'Gentoo Distribution' -G bin,root -s /bin/csh gentoo
[root@centous1 home]# cat /etc/passwd | tail -n 6
tcpdump:x:72:72::/:/sbin/nologin
apache:x:48:48:Apache:/var/www:/sbin/nologin
zabbix:x:500:500::/home/zabbix:/bin/bash
mysql:x:27:27:MySQL Server:/var/lib/mysql:/bin/bash
test:x:1111:1111::/home/test:/bin/sh
gentoo:x:1112:1114:Gentoo Distribution:/home/gentoo:/bin/csh
[root@centous1 home]# groups gentoo
gentoo : gentoo root bin

2、

[root@centous1 ~]# useradd -u 1234 -g bin -G root,ftp -s /bin/csh -d /testdir/testuser testuser
[root@centous1 ~]# cd /testdir/
[root@centous1 testdir]# ls
testuser
[root@centous1 testdir]# getent passwd testuser
testuser:x:1234:1::/testdir/testuser:/bin/csh
[root@centous1 testdir]# groups testuser
testuser : bin root ftp

3、

[root@centous1 home]# usermod -u 4321 -g root -G nobody,ntp -d /home/test -m testuser
[root@centous1 home]# getent passwd testuser
testuser:x:4321:0::/home/test:/bin/csh

4、

[root@centous1 ~]# vim users.txt
[root@centous1 ~]# cat users.txt
user1:x:3000:3000::/testdir/user1:/bin/csh
user2:x:3001:3001::/testdir/user2:/bin/csh
user3:x:3002:3002::/testdir/user3:/bin/csh
user4:x:3003:3003::/testdir/user4:/bin/csh
user5:x:3004:3004::/testdir/user5:/bin/csh
user6:x:3005:3005::/testdir/user6:/bin/csh
user7:x:3006:3006::/testdir/user7:/bin/csh
user8:x:3007:3007::/testdir/user8:/bin/csh
user9:x:3008:3008::/testdir/user9:/bin/csh
user10:x:3009:3009::/testdir/user10:/bin/csh
[root@centous1 ~]# vim pass.txt
[root@centous1 ~]# cat pass.txt | chpasswd
[root@centous1 ~]# cat pass.txt
user1:usernamepass
user2:usernamepass
user3:usernamepass
user4:usernamepass
user5:usernamepass
user6:usernamepass
user7:usernamepass
user8:usernamepass
user9:usernamepass
user10:usernamepass

注:以上创建的用户家目录都没有配置文件,故无法正常登陆;解决办法;

cp -r /etc/skel/.[^.]* 用户家目录