0

I created user 'user11' in Linux and changed its home directory using the -d option but when I login with this user, it shows '-bash-4.3$'.

user mod -d screen shot

I want to know:

  1. What is the meaning of '-bash-4.3' and why does it happen?
  2. Why user11 prints its working directory '/root' and user12 prints '/phome/user12'?
  3. How can I change '-bash-4.3' to it's usual meaning (as user11 or user12)?
Greenonline
  • 2,081

3 Answers3

4

You've tagged your question adduser but you seem to actually be using useradd: AFAIK useradd (unlike adduser) doesn't copy the skeleton files from the /etc/skel directory - in particular, it doesn't create a default ~/.bashrc for the new user.

To answer your questions point-by-point:

  1. it is the default bash shell prompt, used in the absence of a more customized one that is usually provided by the user's ~/.bashrc file

  2. because you didn't create the home directory for user11 (and neither useradd nor usermod -d do that for you)

  3. either copy the default .profile and .bashrc files from /etc/skel into the users' home directories, or delete the user(s) and start over using adduser instead

See What is the difference between adduser and useradd?

steeldriver
  • 136,215
  • 21
  • 243
  • 336
0

Addressing each of your points in turn:

  1. -bash-4.3 is the default prompt for you shell, which is bash. It shows the shell and its version.. The prompt is set by the environment variable PS1. See Bash/Prompt customization.

  2. user11 has a different value of $PS1 to user12. You can verify this by typing echo $PS1 for each user.

  3. In ~/.bashrc, for user12, add the line:

    export PS1="${PWD}> "
    

Where to set PS1

The value of this environment variable can be set in a variety of places. The most common places are /etc/profile, /etc/bashrc, ~/.bash_profile, and ~/.bashrc.

From Setting the PS? Strings Permanently

Johan Kullstam (johan19@idt.net) writes:

The PS1 string should be set in .bashrc. this is because non-interactive bashes go out of their way to unset PS1. the bash man page tells how the presence or absence of PS1 is a good way of knowing whether one is in an interactive vs non-interactive (i.e. script) bash session.

The way I realized this is that startx is a bash script. what this means is, startx will wipe out your prompt. when you set PS1 in .profile (or .bash_profile), login at console, fire up X via startx, your PS1 gets nuked in the process leaving you with the default prompt.

One workaround is to launch xterms and rxvts with the -ls option to force them to read .profile, but any time a shell is called via a non-interactive shell-script middleman PS1 is lost. system(3) uses sh -c which, if sh is bash. will kill PS1. A better way is to place the PS1 definition in .bashrc. This is read every time bash starts and is where interactive things - e.g. PS1 should go.

Therefore it should be stressed that PS1=..blah.. should be in .bashrc and not .profile.

The bash prompt is an extensive subject, and too broad to discuss fully here. For further bash prompt customisation, see Bash Prompt HOWTO.

Greenonline
  • 2,081
0

Concering your questions...

  1. What is the meaning of '-bash-4.3' and why the it happens?

It is the shell used and its version.

  1. why user11 prints it's working directory '/root' and user12 prints '/phome/user12'?

Because user11 does not have a home directory ( /phome/user11 ) in the filesystem.

  1. how can i change '-bash-4.3' to it's usual meaning (as user11 or user12)?

Create a home directory /phome/user11 as specified from getent.

What you have done is that you only have altered the information where to find the user homedirectory, but you did not create one.

Creating a new home directory for user11

cp -a /etc/skel /phome/user11
chown -R user11:1009 /phome/user11

Best would be to use useradd ... -m to create the user homedirectory automatically.

Thomas
  • 6,223