1 创建testuser uid 1234,主组:bin,辅助组:root,ftp,shell:/bin/csh home:/testdir/testuser
[root@localhost ~]# useradd -u 1234 -g bin -G root,ftp -s /bin/csh -d /testdir/testuser testuser
[root@localhost ~]# getent passwd testuser testuser:x:1234:1::/testdir/testuser:/bin/csh [root@localhost ~]# id testuser uid=1234(testuser) gid=1(bin) groups=1(bin),0(root),50(ftp)
2 修改testuser uid:4321,主组:root,辅助组:nobody,loginname:test,home:/home/test 家数据迁移
[root@localhost ~]# usermod -u 4321 -g root -G nobody -l test -d /home/test -m testuser [root@localhost ~]# getent passwd test test:x:4321:0::/home/test:/bin/csh [root@localhost ~]# id test uid=4321(test) gid=0(root) groups=0(root),99(nobody) [root@localhost ~]# ls -a /home/test/ . .. .bash_logout .bash_profile .bashrc .mozilla
3 批量创建帐号:user1...user10,uid:3000-3009,shell:/bin/csh,home:/testdir/username
passwd:usernamepass
[root@localhost ~]# newusers user [root@localhost ~]# tail /etc/passwd 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 | chpasswd [root@localhost ~]# tail /etc/shadow user1:$6$Ro5mq1VJNZ/d$LJ7EDMcsMzU5HNgzP77lk7RLNvYlSAr8uPvX65LwiK4HeiAuMuKkedds5/VS/RMpqiSYJFo4x4cUdIOgsQ8St0:17014:0:99999:7::: user2:$6$iNkD6jcUZY/1nr$DaRBV.VLiNiK5duK.4B1xwVJ1ac4necPXc2nHlBI8LtHVmjAZx5mTxTxLKZ9wtXK6F4aGU1kObto/5pv/3LBO.:17014:0:99999:7::: user3:$6$hxf8tQOsg7/4dv$NjhUwlNVKNdVG6GECkh4M4AnY/XSY7fL4Fn755fRaksY5F2/.qJDQSRQg8Z/PG8xUMg/4gIWcXIyGB5B4x0LC.:17014:0:99999:7::: user4:$6$jECOmMnJQ$hTF0x6ODW8/LgB5/BppwIN7VKDc./73pAS1J46N7eEEzyrXkseMCTcv.ThyqF7/9ET7woKoSSa8elLFdJuIp20:17014:0:99999:7::: user5:$6$cqD4l/pRk/$lwe9foncDm0sP.Gkm8Hpuf/DP43ZFRk5X9PO.5SkdLT0Hp5NgwcebIwbG3rsr5v3Ulv3kGJqMYImAmeb2iiHC0:17014:0:99999:7::: user6:$6$7FLUgUbZX$dooi.T4njASHtXK/ClC.P6jXSpD/KmNI7vnJYInhNtrxQgd16TRp9/LBcvV5i3M6nYlNhM./nc6oCgYt2mPD0.:17014:0:99999:7::: user7:$6$61i05/Op8LE$zpUX6P.PbjwhjmJCje54bCeY6bPy.8/Ub3M9h6F2nAJKCN/MGW4dQTwyd/JRJmVENHHG35288XX3AXNavWyaA0:17014:0:99999:7::: user8:$6$bx0bN/uF8U$eR256H7e8K4O3cUu6iGDyTHpqME.qu3LoC7X/VZxIkAfJWfYGKJug6kRodnelcl4iPxscMrL5WAOX3LyPZ0Zl0:17014:0:99999:7::: user9:$6$bnHrjYn.t$neTwVahU4ME0LAuV/55D0hhzHrHXcRId8h0RhuKTgRxBMj6iI2YL1qu0evzpGi1mrQRa6ONC.XHfM9.gIFiBK1:17014:0:99999:7::: user10:$6$I5Ioe//c6fJ$vFvI/q/bFYeUAIb0vZH80NFlysqbnZyS75/slINeRL.BjrtcGfZ831/PRQAhV1yhBis3PG16ulxnG8G4FJfgQ0:17014:0:99999:7:::
Last login: Tue Aug 2 08:21:35 2016 from 10.1.250.82 [user10@localhost ~]$ pwd /testdir/user10
课堂练习题
1 创建用户gentoo,附加组为bin和root,默认shell为/bin/csh,注释信息为"Gentoo Distribution"
useradd -G bin,root -s /bin/csh -c "Gentoo Distribution" gentoo [root@localhost ~]# id gentoo uid=4322(gentoo) gid=4322(gentoo) groups=4322(gentoo),0(root),1(bin) [root@localhost ~]# groups gentoo gentoo : gentoo root bin [root@localhost ~]# getent passwd gentoo gentoo:x:4322:4322:Gentoo Distribution:/home/gentoo:/bin/csh
2、创建下面的用户、组和组成员关系
名字为admins 的组
用户natasha,使用admins 作为附属组
用户harry,也使用admins 作为附属组
用户sarah,不可交互登录系统,且不是admins 的成员,natasha,harry,sarah密码都是centos
[root@localhost ~]# groupadd admins [root@localhost ~]# useradd -G admins natasha [root@localhost ~]# useradd -G admins harry [root@localhost ~]# useradd -s /etc/nologin sarah [root@localhost ~]# echo "centos" | passwd --stdin natasha Changing password for user natasha. passwd: all authentication tokens updated successfully. [root@localhost ~]# echo "centos" | passwd --stdin harry Changing password for user harry. passwd: all authentication tokens updated successfully. [root@localhost ~]# echo "centos" | passwd --stdin sarah Changing password for user sarah. passwd: all authentication tokens updated successfully. [root@localhost ~]# groups natasha natasha : natasha admins [root@localhost ~]# groups harry harry : harry admins [root@localhost ~]# groups sarah sarah : sarah [root@localhost ~]# getent passwd sarah sarah:x:4325:4326::/home/sarah:/etc/nologin