遇到此種問題,那麼須要瞭解和用戶建立有關的一個目錄(/etc/skel/目錄),此目錄下的全部文件(包括隱藏文件)都會被複制到新添加的用戶的家目錄中。vim
/etc/skel/目錄究竟是幹嗎的呢?
該目錄下是用來存放新用戶環境變量文件的,添加新用戶時,將該目錄習文件拷貝到新用戶家目錄中。默認狀況下該目錄下都是隱藏文件;經過修改、添加、刪除該目錄下的文件,可爲新添加的用戶提供統一的、標準的、初始化用戶環境。bash
顯示/etc/skel/目錄下的全部文件ui
[root@c69-01 ~]# ls -al /etc/skel/ total 20 drwxr-xr-x. 2 root root 4096 Feb 2 21:33 . drwxr-xr-x. 80 root root 4096 Feb 18 09:17 .. -rw-r--r--. 1 root root 18 Mar 23 2017 .bash_logout -rw-r--r--. 1 root root 176 Mar 23 2017 .bash_profile -rw-r--r--. 1 root root 124 Mar 23 2017 .bashrc
添加新用戶,體現目錄/etc/skel/做用:
上面說到/etc/skel/目錄下的全部文件都會被拷貝到新用戶的家目錄中,那麼咱們在/etc/skel/下建立一個README文件,在建立新用戶以後,新用戶家目錄中是否有該文件的存在this
1)使用超級用戶root建立文件READMEspa
[root@c69-01 ~]# vim /etc/skel/README [root@c69-01 ~]# cat /etc/skel/README WELCOME Please read the contents of this document carefully! ............................ ............................ ............................ ............................ [root@c69-01 ~]# ls -al /etc/skel/ total 24 drwxr-xr-x. 2 root root 4096 Feb 18 09:34 . drwxr-xr-x. 80 root root 4096 Feb 18 09:17 .. -rw-r--r--. 1 root root 18 Mar 23 2017 .bash_logout -rw-r--r--. 1 root root 176 Mar 23 2017 .bash_profile -rw-r--r--. 1 root root 124 Mar 23 2017 .bashrc -rw-r--r-- 1 root root 179 Feb 18 09:34 README2)使用超級用戶建立新用戶user01命令行
[root@c69-01 ~]# id user01 id: user01: No such user [root@c69-01 ~]# useradd user01 [root@c69-01 ~]# id user01 uid=1010(user01) gid=1010(user01) groups=1010(user01) [root@c69-01 ~]# ls -al /home/user01/ total 24 drwx------ 2 user01 user01 4096 Feb 18 09:36 . drwxr-xr-x. 15 root root 4096 Feb 18 09:36 .. -rw-r--r-- 1 user01 user01 18 Mar 23 2017 .bash_logout -rw-r--r-- 1 user01 user01 176 Mar 23 2017 .bash_profile -rw-r--r-- 1 user01 user01 124 Mar 23 2017 .bashrc -rw-r--r-- 1 user01 user01 179 Feb 18 09:34 README能夠看到新用戶的家目錄下存在README文件code
[root@c69-01 ~]# cat /home/user01/README WELCOME Please read the contents of this document carefully! ............................ ............................ ............................ ............................文件內容和/etc/skel/README文件內容同樣登錄
-bash-4.1$ 問題重現:
1)切換到普通用戶,刪除家目錄中全部.bash*文件,退出從新登陸,便可看到想要的命令行提示變量
[root@c69-01 ~]# su - user01 [user01@c69-01 ~]$ ls -al total 24 drwx------ 2 user01 user01 4096 Feb 18 09:36 . drwxr-xr-x. 15 root root 4096 Feb 18 09:36 .. -rw-r--r-- 1 user01 user01 18 Mar 23 2017 .bash_logout -rw-r--r-- 1 user01 user01 176 Mar 23 2017 .bash_profile -rw-r--r-- 1 user01 user01 124 Mar 23 2017 .bashrc -rw-r--r-- 1 user01 user01 179 Feb 18 09:34 README [user01@c69-01 ~]$ \rm .bash* [user01@c69-01 ~]$ logout [root@c69-01 ~]# su - user01 -bash-4.1$上面說到,該目錄下是用來存放新用戶環境變量文件的,刪除這些文件,就會出現問題,那麼如何解決呢?file
-bash-4.1$ 問題解決:
1)使用普通用戶user01,拷貝目錄/etc/skel/下的文件.bash*文件到普通用戶家目錄下便可,退出從新登陸,便可解決該問題。
-bash-4.1$ cp /etc/skel/.bash* . -bash-4.1$ ls -al total 28 drwx------ 2 user01 user01 4096 Feb 18 09:45 . drwxr-xr-x. 15 root root 4096 Feb 18 09:36 .. -rw------- 1 user01 user01 18 Feb 18 09:42 .bash_history -rw-r--r-- 1 user01 user01 18 Feb 18 09:45 .bash_logout -rw-r--r-- 1 user01 user01 176 Feb 18 09:45 .bash_profile -rw-r--r-- 1 user01 user01 124 Feb 18 09:45 .bashrc -rw-r--r-- 1 user01 user01 179 Feb 18 09:34 README -bash-4.1$ logout [root@c69-01 ~]# su - user01
總結:
經過該問題,應該瞭解用戶建立的過程,瞭解目錄/etc/skel/做用
注:我使用的系統爲:CentOS release 6.9 (Final)