Marco Education-August 1 small homework after class (Linux Create Users, batch create users)

Source: Internet
Author: User

1. Create TestUser UID 1234, main group: Bin, Auxiliary Group: ROOT,FTP,SHELL:/BIN/CSH Home:/testdir/testuser

[Email protected] ~]# useradd testuser-u 1234-g bin-g root,ftp-s/bin/csh-d/testdir/testuser[[email protected] ~]# grep testuser/etc/passwdtestuser:x:1234:1::/testdir/testuser:/bin/csh


2, modify TestUser uid:4321, main group: root, Auxiliary Group: Nobody,loginname:test,home:/home/test Home Data migration

[Email protected] ~]# usermod-u 4321-g root-g nobody,loginname-c "test"-d/home/test-m Testuser[[email protected] ~ ]# cat/etc/passwd |grep testusertestuser:x:4321:0:test:/home/test:/bin/csh


3, Batch create account: User1...user10

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

Passwd:usernamepass

Note Home directory-related configuration, so that users log on normally


Scenario One: Script mode

[[email protected] ~]# Cat add.shfor username in user{1..10}dofor uid in 300{0..9}doif [-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!" Fidonedone

Scenario Two: Text templates

[Email protected] ~]# VI userlist #账户文件

USER1:X:3000:3000:HOME:/TESTDIR/USER1:/BIN/CSHUSER2:X:3001:3001:HOME:/TESTDIR/USER2:/BIN/CSHUSER3:X:3002:3002: home:/testdir/user3:/bin/cshuser4:x:3003:3003:home:/testdir/user4:/bin/cshuser5:x:3004:3004:home:/testdir/ user5:/bin/cshuser6:x:3005:3005:home:/testdir/user6:/bin/cshuser7:x:3006:3006:home:/testdir/user7:/bin/ Cshuser8:x:3007:3007:home:/testdir/user8:/bin/cshuser9:x:3008:3008:home:/testdir/user9:/bin/cshuser10:x : 3009:3009:home:/testdir/user10:/bin/csh

Application files

[Email protected] ~]# newusers userlist


[Email protected] ~]# VI passlist #密码文件

User1:user1passuser2:user2passuser3:user3passuser4:user4passuser5:user5passuser6:user1passuser7:user1passuser8 : User1passuser9:user1passuser10:user1pass

[email protected] ~]# Cat P.txt | chpasswd

Copy user-created initialization files to the new user home directory (follow the bad copy to all user home directories)

[[email protected] ~]# for Userdir in user{1..10};d o cp-r/etc/skel/. [^.] * $userdir;d O


This article from "Live by the Sea like Waves" blog, please be sure to keep this source http://zhang789.blog.51cto.com/11045979/1833704

Marco Education-August 1 small homework after class (Linux Create Users, batch create users)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.