Ubuntu 添加新用戶並制定目錄和shell


 

分類: LINUX

2011-07-07 15:22:54

 

ubuntu新建的用戶並沒有新建相應的home目錄和對應的shell環境。

 下面就總結一下如何的在ubuntu下建立用戶並配置新的shell。

涉及的命令有useradd ,  userdel, usermod.

1.  

 root@yw-desktop:/home# useradd -r -m -s /bin/bash yuanwei
root@yw-desktop:/home# ls
yuanwei  yw
root@yw-desktop:/home# cd yuanwei/
root@yw-desktop:/home/yuanwei# ls -a
.  ..  .bash_logout  .bashrc  examples.desktop  .profile
root@yw-desktop:/home/yuanwei# ll -a
總用量 24
drwxr-xr-x 2 yuanwei yuanwei 4096 2011-07-07 02:46 ./
drwxr-xr-x 4 root    root    4096 2011-07-07 02:46 ../
-rw-r--r-- 1 yuanwei yuanwei  220 2010-04-19 09:51 .bash_logout
-rw-r--r-- 1 yuanwei yuanwei 3103 2010-04-19 09:51 .bashrc
-rw-r--r-- 1 yuanwei yuanwei  179 2010-03-26 20:31 examples.desktop
-rw-r--r-- 1 yuanwei yuanwei  675 2010-04-19 09:51 .profile
root@yw-desktop:/home/yuanwei# 



 

 

 

上面的2個紅色方框的文件很熟悉把, .bashrc 這個文件的環境變量對應這個所在的好用戶的目錄。也就對應該用戶的變量了。  .profile 這個文件和上面的有包含和被包含的關系。 這里不贅述了。
5. 后來運行gksudognome-terminal開了一個root權限的終端,修改/etc/sudoer的權限為740,編輯它的內容, 把%adminALL=(ALL) ALL修改為%admin ALL=NOPASSWD: ALL,保存,再將權限改為440。這下子使用sudo連密碼也不需要輸入了 .

 

 

補充]
所有用戶信息在/etc/passwd里可以看到, 包括啟用何種shell.

 

如 果用sudo時提示"xxx is not in the sudoers file. This incident will be reported.其中XXX是你的用戶名,也就是你的用戶名沒有權限使用sudo,我們只要修改一下/etc/sudoers文件就行了。下面是修改方 法:

1)進入超級用戶模式。也就是輸入"su -",系統會讓你輸入超級用戶密碼,輸入密碼后就進入了超級用戶模式。(當然,你也可以直接用root用) 

2)添加文件的寫權限。也就是輸入命令"chmod u+w /etc/sudoers"。 
3)編輯/etc/sudoers文件。也就是輸入命令"vim /etc/sudoers",輸入"i"進入編輯模式,找到這一 行:"root ALL=(ALL) ALL"在起下面添加"xxx ALL=(ALL) ALL"(這里的xxx是你的用戶名),然后保存(就是先按一 下Esc鍵,然后輸入":wq")退出。 
4)撤銷文件的寫權限。也就是輸入命令"chmod u-w /etc/sudoers"。


 

用recovery mode模式啟動后,進入命令行模式,提示符應該是 #

1、輸入用戶管理的命令,新建用戶(以test為例):
useradd test

修改 test 用戶的密碼:
passwd test

2、將新用戶添加到管理組:
gpasswd -a test admin

3、給 test 用戶創建自己的目錄:
cd /home

mkdir test

chown test /home/test

4、重新啟動,
reboot

然后用 test 登錄,

登錄以后,點菜單“系統-系統管理-用戶和組”,進去選中你的用戶,點右邊的“屬性”按鈕,到用戶權限里打勾需要的;

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM