iT邦幫忙

0

linux使用newusers建立出來的帳號沒有bash_profile等檔案

因為需要建立帳號的user人數眾多,所以使用newusers搭配清單的方式建立數百位user帳號。

發現使用newusers建立出來的使用者帳號家目錄底下,皆無.bash_logout、.bash_profile、.bashrc這3個檔案,但若是使用useradd指令建出來的帳號,帳號的家目錄底下則有.bash_logout、.bash_profile、.bashrc這3個檔案。

請問若想要一口氣建立數百位user,並能達到像newusers一樣直接指定好帳號密碼,又能在使用者家目錄底下產生.bash_logout、.bash_profile、.bashrc這3個檔案,能有什麼做法呢?

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

4
wiseguy
iT邦超人 1 級 ‧ 2015-08-27 16:41:57
最佳解答

就建完後自己 copy 就好了,有這麼難嗎?

<pre class="c" name="code">cd /home
for u in `ls -1`
do
cp /etc/skel/.bash* $u/
chown -R $u $u
done
jessezero iT邦新手 5 級 ‧ 2015-08-28 10:34:32 檢舉

對shell scripts不是很熟,所以起手寫scripts真的有難度......。

由於我手邊有user帳號清單,所以將shell scripts稍微改了一下

<pre class="c" name="code">
#!/bin/bash

while read user; do
cd /home
cp /etc/skel/.bash* $user/
chown -R $user:$user $user
done <user-list

最後,還是謝謝W大的幫忙,感謝!

我要發表回答

立即登入回答