歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux技術

馬哥教育面授

1、創建testuser uid 1234,主組:bin,輔助組:root,ftp,shell:/bin/csh home:/testdir/testuser

[root@localhost ~]# useradd testuser -u 1234 -g bin -G root,ftp -s /bin/csh -d /testdir/testuser
[root@localhost ~]# grep testuser /etc/passwd
testuser:x:1234:1::/testdir/testuser:/bin/csh
2、修改testuser uid:4321,主組:root,輔助組:nobody,loginname:test,home:/home/test 家數據遷移

[root@localhost ~]# usermod -u 4321 -g root -G nobody,loginname -c "test" -d /home/test -m testuser
[root@localhost ~]# cat /etc/passwd |grep testuser
testuser:x:4321:0:test:/home/test:/bin/csh
3、批量創建帳號:user1...user10

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

passwd:usernamepass

注意家目錄相關配置,使用戶正常登錄

方案一:腳本方式

[root@localhost ~]# cat add.sh
for username in user{1..10}
do
for uid in 300{0..9}
do
if [ -n $username ]
    then
    useradd $username -u $uid -s /bin/csh -c "home" -d /testdir/$username
    echo
    echo $username"pass" | passwd --stdin $username
    echo
    echo "User $username's password is changed!"
    else
    echo "the username is null!"
fi
done
done
方案二:文本模板[root@localhost ~]# vi userlist #賬戶文件

user1:x:3000:3000:home:/testdir/user1:/bin/csh
user2:x:3001:3001:home:/testdir/user2:/bin/csh
user3:x:3002:3002:home:/testdir/user3:/bin/csh
user4:x:3003:3003:home:/testdir/user4:/bin/csh
user5:x:3004:3004:home:/testdir/user5:/bin/csh
user6:x:3005:3005:home:/testdir/user6:/bin/csh
user7:x:3006:3006:home:/testdir/user7:/bin/csh
user8:x:3007:3007:home:/testdir/user8:/bin/csh
user9:x:3008:3008:home:/testdir/user9:/bin/csh
user10:x:3009:3009:home:/testdir/user10:/bin/csh
應用文件
[root@localhost ~]# newusers userlist

[root@localhost ~]# vi passlist #密碼文件

user1:user1pass
user2:user2pass
user3:user3pass
user4:user4pass
user5:user5pass
user6:user1pass
user7:user1pass
user8:user1pass
user9:user1pass
user10:user1pass
[root@localhost ~]# cat p.txt | chpasswd把用戶創建初始化文件拷貝到新的用戶家目錄(循壞拷貝到所有用戶家目錄)

[root@localhost ~]# for userdir in user{1..10};do cp -r /etc/skel/.[^.]* $userdir;do
本文出自 “家住海邊喜歡浪” 博客,請務必保留此出處http://zhang789.blog.51cto.com/11045979/1833704

Copyright © Linux教程網 All Rights Reserved