After the Linux ordinary user logs in, the command line prompts: -bash-4.1$, cause analysis and solution

    If you encounter such a problem, you need to know a directory ( /etc/skel/ directory) related to user creation . All files (including hidden files) in this directory will be copied to the home directory of the newly added user.

What exactly is the /etc/skel/ directory doing?

    This directory is used to store the new user environment variable file. When adding a new user, copy the directory learning file to the new user's home directory. By default, all files in this directory are hidden; by modifying, adding and deleting files in this directory, a unified, standard and initialized user environment can be provided for newly added users.

Display all files in /etc/skel/ directory

[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

Add a new user, reflecting the role of the directory /etc/skel/:

    As mentioned above , all files in the /etc/skel/ directory will be copied to the new user's home directory. Then we create a README file under /etc/skel/ . After creating a new user, is the new user's home directory? the existence of the file

1) Create the file README with superuser root

[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 README

2) Create a new user user01 with superuser

[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

You can see that there is a README file in the new user's home directory

[root@c69-01 ~]# cat /home/user01/README 
WELCOME 
Please read the contents of this document carefully!

............................
............................
............................
............................

The content of the file is the same as that of the /etc/skel/README file

-bash-4.1$ Problem reproduces:

1) Switch to the normal user, delete all .bash* files in the home directory, log out and log in again, you can see the desired command line prompt

[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$ 

As mentioned above, this directory is used to store new user environment variable files. If these files are deleted, problems will arise, so how to solve them?

-bash-4.1$ Problem solved:

1) Use the ordinary user user01, copy the .bash* files in the directory /etc/skel/ to the ordinary user's home directory, log out and log in again to solve the problem.

-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

Summarize:

    Through this question, you should understand the process of user creation and understand the role of the directory /etc/skel/

 

Note: The system I use is : CentOS release 6.9 (Final)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325341879&siteId=291194637