您的位置:首页 > 其它

8.1用户及组管理作业

2016-08-02 14:03 134 查看
1、创建testuser uid 1234,主组:bin,辅助组:root,ftp,shell:/bin/csh home:/testdir/testuser
[root@qzx ~]# useradd testuser -u 1234 -g bin -G root,ftp -s /bin/csh -d /testdir/testuser
[root@qzx ~]# getent passwd testusertestuser:x:1234:1::/testdir/testuser:/bin/csh
[root@qzx ~]# groups testuser
testuser : bin root ftp
2、修改testuser uid:4321,主组:root,辅助组:nobody,lo
ginname:test,home:/home/test 家数据迁移
[root@qzx ~]# usermod testuser -u 4321 -g root -G nobody,loginname,test -md /home/test
[root@qzx ~]# getent passwd testusertestuser:x:4321:0::/home/test:/bin/csh
[root@qzx ~]# groups testusertestuser : root nobody loginname test
3、批量创建帐号:user1...user10
uid:3000-3009,shell:/bin/csh,home:/testdir/username
passwd:usernamepass
注意家目录相关配置,使用户正常
登录
首先创建用户文件和密码文件
[root@localhost ~]# cat
cat        catchsegv  catman
[root@localhost ~]# cat textuser.test
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@localhost ~]# cat passwd.text
user1:user1passwd
user2:user2passwd
user3:user3passwd
user4:user4passwd
user5:user5passwd
user6:user6passwd
user7:user7passwd
user8:user8passwd
user9:user9passwd
user10:user10passwd
批量创建用户
[root@localhost ~]# newusers textuser.test
批量改密码
[root@localhost ~]# cat passwd.text | chpasswd
复制家目录相关配置
[root@localhost ~]# cp -a /etc/skel/. /testdir/user1
[root@localhost ~]# cp -a /etc/skel/. /testdir/user2
[root@localhost ~]# cp -a /etc/skel/. /testdir/user3
[root@localhost ~]# cp -a /etc/skel/. /testdir/user4
[root@localhost ~]# cp -a /etc/skel/. /testdir/user5
[root@localhost ~]# cp -a /etc/skel/. /testdir/user6
[root@localhost ~]# cp -a /etc/skel/. /testdir/user7
[root@localhost ~]# cp -a /etc/skel/. /testdir/user8
[root@localhost ~]# cp -a /etc/skel/. /testdir/user9
[root@localhost ~]# cp -a /etc/skel/. /testdir/user10
切换用户
[user1@localhost ~]$ su - user2
密码:
[user2@localhost ~]$ ls -al
总用量 16
drwx------.  3 user2 user2   74 8月   2 13:56 .
drwxr-xr-x. 12 root  root  4096 8月   2 13:30 ..
-rw-r--r--.  1 user2 user2   18 8月   2 13:56 .bash_logout
-rw-r--r--.  1 user2 user2  193 8月   2 13:56 .bash_profile
-rw-r--r--.  1 user2 user2  231 8月   2 13:56 .bashrc
drwxr-xr-x.  4 user2 user2   37 8月   2 13:56 .mozilla
上课练习
1、创建用户gentoo,附加组为bin和root,默认shell为/bin/csh,注释信息为"Gentoo Distribution"
[root@qzx ~]# useradd gentoo -G bin,root -s /bin/csh -c "Gentoo Distribtion"
[root@qzx ~]# groups gentoo
gentoo : gentoo root bin
[root@qzx ~]# getent passwd gentoo
gentoo:x:4323:4323:Gentoo Distribtion:/home/gentoo:/bin/csh
2、创建下面的用户、组和组成员关系
名字为admins 的组
用户natasha,使用admins 作为附属组
用户harry,也使用admins 作为附属组
用户sarsh,不可交互登录系统,且不是admins 的成员,
natasha,harry,sarsh密码都是centos
[root@qzx ~]# groupadd admins

[root@qzx ~]# useradd natasha -G admins
[root@qzx ~]# useradd harry -G admins

[root@qzx ~]# useradd sarsh -s /sbin/nologin
[root@qzx ~]# getent passwd sarsh
sarsh:x:4326:4327::/home/sarsh:/sbin/nologin

[root@qzx ~]# echo "centos"|passwd --stdin natasha
Changing password for user natasha.
passwd: all authentication tokens updated successfully.
[root@qzx ~]# echo "centos"|passwd --stdin harry
Changing password for user harry.
passwd: all authentication tokens updated successfully.
[root@qzx ~]# echo "centos"|passwd --stdin sarah
passwd: Unknown user name 'sarah'.
[root@qzx ~]# echo "centos"|passwd --stdin sarsh
Changing password for user sarsh.
passwd: all authentication tokens updated successfully.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  用户