遇到此种问题,那么须要了解和用户建立有关的一个目录(/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)