新聞中心
linux系統(tǒng)比較流行的Linux的分支有Redhat,CentOS,Ubuntu等,他們都有一個共同的特征,即多用戶,系統(tǒng)管理需要為每個用戶創(chuàng)建不同的賬號并且賦予權(quán)限。 用戶賬號創(chuàng)建也是Linux系統(tǒng)管理者必不可少的一項技能,下面介紹一下,Linux下的用戶批量創(chuàng)建:

1. 如果需要創(chuàng)建10個以上的用戶,建議使用shell腳本的方式進(jìn)行創(chuàng)建,下面的代碼實現(xiàn)了為user1-user10創(chuàng)建賬戶的操作:
#!/bin/bash
user1=user1
user2=user2
user3=user3
….
usern=usern
for i in $(seq 1 10):
do
user=”user$i”
useradd $user
done
2. 如果需要批量創(chuàng)建比較多的用戶,可以使用useradd系統(tǒng)命令來實現(xiàn),例如:
/usr/sbin/useradd -D -b /home -s /bin/bash
這個命令會創(chuàng)建100個用戶帳號,以50開頭,然后每個用戶家目錄放在/home/user_name中,默認(rèn)shell為/bin/bash。
3. 對于更復(fù)雜的用戶創(chuàng)建,我們可以使用expect命令來完成,例如:
# 使用 expect 快速添加用戶
#
# 作者:https://linux.cn
#!/usr/bin/expect
# 設(shè)定用戶信息
SET username admin
set password admin123
set usernumber 10
# 使用for循環(huán)創(chuàng)建用戶
for {set i 0} {$i
set m [expr $i+1]
spawn useradd $username$m
expect “yes/no*” {send “yes\r”}
expect “New*” {send “$password\r”}
expect “Retype*” {send “$password\r”}
expect eof
}
以上就是本文關(guān)于Linux下的用戶批量創(chuàng)建的介紹,有了以上方法,系統(tǒng)管理就可以快速搭建多用戶環(huán)境,進(jìn)而利用用戶來控制終端權(quán)限,從而提高了Linux系統(tǒng)的安全性。
成都創(chuàng)新互聯(lián)科技有限公司,經(jīng)過多年的不懈努力,公司現(xiàn)已經(jīng)成為一家專業(yè)從事IT產(chǎn)品開發(fā)和營銷公司。廣泛應(yīng)用于計算機(jī)網(wǎng)絡(luò)、設(shè)計、SEO優(yōu)化、關(guān)鍵詞排名等多種行業(yè)!
新聞名稱:linux下的用戶批量創(chuàng)建(linux批量創(chuàng)建用戶)
文章URL:http://m.fisionsoft.com.cn/article/cdjedji.html


咨詢
建站咨詢
