登录环境故障解决
登录环境故障-bash-4.1的原因一般是因为用户删除文件的时候,把当前用户的家目录的一些隐藏文件删除所导致的。.bashrc .bash_profile
没了,与用户有关的环境变量也没了。
- 首先咱们先创建一个test用户
[root@summer home]# groupadd test
[root@summer home]# useradd -g test test
[root@summer home]# echo 123 | passwd test --stdin
Changing password for user test.
passwd: all authentication tokens updated successfully.
[root@summer home]# chage -M 99999 test
1
2
3
4
5
6
2
3
4
5
6
- 创建完成后会在home目录下自动生成一个test用户目录
[root@summer home]# ll
total 74400
drwxr-xr-x 8 root root 4096 Oct 12 15:32 code-server-3.6.0-linux-amd64
-rw-rw-rw- 1 root root 76150543 Oct 14 22:11 code-server-3.6.0-linux-amd64.tar.gz
-rw-r--r-- 1 root root 13857 Oct 10 14:07 get-docker.sh
drwxr-xr-x 5 root root 4096 Oct 31 17:55 summer
drwx------ 2 test test 4096 Nov 18 14:11 test
[root@summer home]# su test
[test@summer home]$ ll
total 74400
drwxr-xr-x 8 root root 4096 Oct 12 15:32 code-server-3.6.0-linux-amd64
-rw-rw-rw- 1 root root 76150543 Oct 14 22:11 code-server-3.6.0-linux-amd64.tar.gz
-rw-r--r-- 1 root root 13857 Oct 10 14:07 get-docker.sh
drwxr-xr-x 5 root root 4096 Oct 31 17:55 summer
drwx------ 2 test test 4096 Nov 18 14:11 test
[test@summer home]$ exit
exit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
- 此时模拟误删了用户目录的操作
[root@summer home]# rm -rf test/
[root@summer home]# ll
total 74396
drwxr-xr-x 8 root root 4096 Oct 12 15:32 code-server-3.6.0-linux-amd64
-rw-rw-rw- 1 root root 76150543 Oct 14 22:11 code-server-3.6.0-linux-amd64.tar.gz
-rw-r--r-- 1 root root 13857 Oct 10 14:07 get-docker.sh
drwxr-xr-x 5 root root 4096 Oct 31 17:55 summer
drwxr-xr-x 8 root root 4096 Oct 12 20:52 vuepress-theme-vdoing-master
[root@summer home]# su test
bash-4.2$
bash-4.2$
bash-4.2$
bash-4.2$
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
- 可以看到切换test用户后命令行变为了
bash-4.2$
# 解决办法
把用户老家root的模板/etc/skel下面的.bash_profile和.bashrc复制到出问题的用户
- 在home下新建test文件夹并赋予用户和用户组
[root@summer home]# mkdir test
[root@summer home]# ll
total 74400
drwxr-xr-x 8 root root 4096 Oct 12 15:32 code-server-3.6.0-linux-amd64
-rw-rw-rw- 1 root root 76150543 Oct 14 22:11 code-server-3.6.0-linux-amd64.tar.gz
-rw-r--r-- 1 root root 13857 Oct 10 14:07 get-docker.sh
drwxr-xr-x 5 root root 4096 Oct 31 17:55 summer
drwxr-xr-x 2 root root 4096 Nov 18 14:24 test
[root@summer home]# chown -R test:test test/
[root@summer home]# ll
total 74400
drwxr-xr-x 8 root root 4096 Oct 12 15:32 code-server-3.6.0-linux-amd64
-rw-rw-rw- 1 root root 76150543 Oct 14 22:11 code-server-3.6.0-linux-amd64.tar.gz
-rw-r--r-- 1 root root 13857 Oct 10 14:07 get-docker.sh
drwxr-xr-x 5 root root 4096 Oct 31 17:55 summer
drwxr-xr-x 2 test test 4096 Nov 18 14:24 test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
- 复制.bash_profile和.bashrc
[root@summer home]# cd test/
[root@summer test]# su test
bash-4.2$ pwd
/home/test
bash-4.2$ cp /etc/skel/.bash* ~
bash-4.2$ exit
exit
[root@summer test]# su test
[test@summer ~]$
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
上次更新: 1/14/2021, 6:11:51 PM