请问如下登录环境故障的原理及解决办法?
1
2
|
-
bash
-4.1$
-
bash
-4.1$
|
此情况一般是因为用户删除文件的时候,把当前用户的家目录的一些隐藏文件删除所导致的(把自己老家端了)。
导致.bashrc .bash_profile没了,与用户有关的环境变量也没了。
1
2
3
4
5
|
[root@show ~]
# ll -a .bash*
-rw-------. 1 root root 32635 Apr 11 23:30 .bash_history
-rw-r--r-- 1 root root 41 Jun 25 2016 .bash_logout
-rw-r--r-- 1 root root 176 Sep 6 2016 .bash_profile
-rw-r--r-- 1 root root 177 Sep 6 2016 .bashrc
|
-
解决方法:把用户老家的模板/etc/skel下面的
1
2
3
4
5
6
7
|
[root@show ~]
# ll -a /etc/skel/
total 28
drwxr-xr-x. 2 root root 4096 Dec 3 2015 .
drwxr-xr-x. 87 root root 12288 Apr 10 09:06 ..
-rw-r--r--. 1 root root 18 Sep 23 2015 .bash_logout
-rw-r--r--. 1 root root 176 Sep 23 2015 .bash_profile
###复制这个文件到出问题的用户家里
-rw-r--r--. 1 root root 124 Sep 23 2015 .bashrc
###复制这个文件到出问题的用户家里
|
假设当前用户
-
切换到出问题的用户
1
2
3
|
-
bash
-4.1$
whoami
oldgirl
-
bash
-4.1$
|
-
复制用户老家的模板给出问题的用户
1
2
3
4
5
6
7
8
9
|
-
bash
-4.1$
cp
/etc/skel/
.
bash
* ~
-
bash
-4.1$ll -a
total24
drwx------ 2 oldgirl incahome 4096 Feb 14 15:07 .
drwxr-xr-x.10 root root 4096 Feb 14 14:53 ..
-rw------- 1 oldgirl incahome 14 Feb 14 15:05 .bash_history
-rw-r--r-- 1 oldgirl incahome 18 Feb 14 15:07 .bash_logout
-rw-r--r-- 1 oldgirl incahome 176 Feb 14 15:07 .bash_profile
-rw-r--r-- 1 oldgirl incahome 124 Feb 14 15:07 .bashrc
|
-
重新登录进行测试
1
2
3
|
-
bash
-4.1$
logout
[root@oldboyedu~]
# su - oldgirl
[oldgirl@oldboyedu~]$
|
-
可以参考下图,简易说明了添加用户的过程。
本文转自 李导 51CTO博客,原文链接:http://blog.51cto.com/lidao/1915110