我想添加linux用戶,然後我想盡可能地限制它們。 (noshell等)從一個名爲用戶的文件。Linux bash從文件讀取然後adduser到linux
這是我的代碼,但不工作:
while read line
do
input = echo ($input | tr ":" "\n")
#!/bin/bash
# Script to add a user to Linux system
if [ $(id -u) -eq 0 ]; then
if [ $? -eq 0 ]; then
echo "$username exists!"
exit 1
else
pass=$(perl -e 'print crypt($ARGV[0], "password")' $input[1)
useradd -m -p $input[1] $input[0]
[ $? -eq 0 ] && echo "User has been added to system!" || echo "Failed to add a user!"
fi
else
echo "Only root may add a user to the system"
exit 2
fi
done < /var/www/users
然後我想限制他們與noshell賬戶。 (但我知道我該怎麼做,但我不能輸入正確地文件分開:/)
輸入(用戶):
john:lol
rambo:sanyi
cula:kari
非常感謝您!
它看起來像Mandar已經回答了你的問題,但以供將來參考,shebang行'#/斌/ bash'應該是非常_first_線!你的腳本。它在你的腳本中間沒用。因此,在通過複製和粘貼創建腳本時,您需要更加謹慎。 :) – 2014-09-27 16:31:41