linux手動增加使用者:
那麼我們已經知道如何新增帳號與刪除甚至是修改帳號了,呵呵!是否從此之後,天下太平呢?當然不是了!為什麼呢?假設您今天要新增帳號的內容是『數字帳號』的話,那麼是否可以使用 useradd 新增帳號呢?例如:
useradd 1234567
很抱歉?useradd 並不允許這樣的帳號設定的!唉?真難過,難道沒有其他的方法可以新增這樣的使用者帳號了嗎?咦!剛剛不是說過,其實我們都是使用 /etc/passwd 及 /etc/shadow 這幾個檔案來設定帳號的嗎?那麼使用手動的方式是否就可以解決這樣的困擾了!Bingo !沒錯!就是這樣!所以底下我們嘗試使用手動的方式來新增帳號,試試看能不能成功的增加一個使用者 1234 呢?• 一般使用者帳號的增加:

現在我們知道其實使用 userconf 、 useradd 與 groupadd 其實會用到的檔案最鮮明的就是 /etc/passwd 與 /etc/shadow 囉!那麼如何手動的增加一個使用者呢?最大的困擾在於 passwd 與 shadow 的同步啦!OK!大致的步驟可以這樣說:1. 先建立所需要的群組( vi /etc/group )
2. 建立帳號的各個屬性( vi /etc/passwd )
3. 將 passwd 與 shadow 同步化 ( pwconv )
4. 建立該帳號的密碼 ( passwd acount )
5. 建立使用者家目錄 ( cp -r /etc/skel /home/account )
6. 更改家目錄屬性 ( chown -R account.group /home/account )
這樣就 OK 啦!實地的來新增一個 test 群組與帳號來試試看:
 
建立新的群組 test ,設其 GID 為 520
[root @test /root ]# vi /etc/group
----略
test:x:520:test               <==新增群組,且群組的人為 test ,GID 為 520
建立 test 的各個屬性
[root @test /root ]# vi /etc/passwd
----略
test:x:520:520:testing account:/home/test:/bin/bash   <==建立各個屬性

同步化 /etc/passwd 與 /etc/shadow
[root @test /root ]# pwconv         <==將 passwd 的資料轉入 /etc/shadow 中!

建立密碼
[root @test /root ]# passwd test    <==建立使用者 test 密碼
Changing password for user test
New password:
Retype new password:
passwd: all authentication tokens updated successfully

建立家目錄並轉化家目錄的擁有者
[root @test /root ]# cp -r /etc/skel /home/test
[root @test /root ]# chown -R test:test /home/test
 

這樣就建立完畢囉!!很簡單吧!而由上面的例子,其實您也可以依據此而使用 scripts 來新增使用者。

文章來源:鳥哥網站

arrow
arrow

    Johnson峰 發表在 痞客邦 留言(0) 人氣()