I'm switching user using command:

sudo su - userName

On my terminal I always have:

user@user directory $ (some command)

But when I switch user I have only :

$ (some commands)

It is hard to explain what I mean but I'm new in linux and I have't found this in other questions. How to keep this whole data before $ sign after relogin?

Edit: Ok It work for me I recreated user using command: adduser name

But I have another question. This command create /home directory but It is empty. Is some command to initialize /home for new user?

  • Which distro are you using?
    – Graeme
    Mar 30, 2014 at 13:40
  • Your new user's $ENVironment is not being sourced. You can do so with . /home/new_user/.profile
    – mikeserv
    Mar 30, 2014 at 13:40
  • 2
    The home directory created should contain some hidden files. You can see them with ls -a. These are copied from /etc/skel.
    – Graeme
    Mar 30, 2014 at 15:37

3 Answers 3


But I have another question. This command create /home directory but It is empty. Is some command to initialize /home for new user?

The solution to the second question will also solve the first one. Your new user doesn't have all the default configuration files in it's home directory and therefore the new shell doesn't show a fancy prompt, etc...

The standard command to create a new user and initialize its home directory using the contents of /etc/skel is:

useradd -m

And as has been stated, some distributions have wrong defaults, so you may want to add more options:

useradd -m -s /bin/bash

For more details, use:

man useradd

There are some fancy higher level tools specific to distributions. One example, used on Debian and the like, was already mentioned in comments to your question:


Also, there is configuration in /etc that can make useradd behave as useradd -m but IMO it's better to learn to use the -m always to avoid being affected by different installations and distributions.

From comments above, it's possible to set the defaults using -D argument to useradd:

useradd -D -s /path/to/default/shell
  • 1
    Please also to refer to @Graeme's comment above on /etc/skel
    – mikeserv
    Mar 30, 2014 at 20:10
  • 1
    Also the configuration you mention can be interfaced on the command line with useradd -D.
    – mikeserv
    Mar 30, 2014 at 20:12
  • Anyone please feel free to use the stack exchange feature to edit answers. I may or may not get to updating it myself. Mar 30, 2014 at 21:16

You are switching for a normal user and this user doesn't have a $PS1 set but in my opnion you add this user using useradd command in Debian Based that by default the shell wen you use useradd is sh , so you can try:

chsh -s /bin/bash userName

this command will change the shell for userName to /bin/bash. and than try again switch for that user. if you want to change the default shell for a bash when you add some user using useradd you can change the file /etc/default/useradd.

sed -i -e "s@\(^SHELL\).*@\1=/bin/bash@g" /etc/default/useradd
  • 2
    If it is a Debian based distro, this is most likely the cause of the problem since a fancy prompt is only set for bash by default. Although note that for Debian distros it is recommended to use adduser instead of useradd. See - unix.stackexchange.com/questions/121071/…
    – Graeme
    Mar 30, 2014 at 14:09
  • 1
    Graeme in my opnion I think is better for new users try learn how to use useradd instead adduser because adduser is just for Debian Based and useradd have in all distros. Mar 30, 2014 at 14:12
  • 2
    Well, there's also useradd -s /path/to/preferred/shell username and, if you don't feel like doing that every time, useradd -D -s /path/to/default/shell.
    – mikeserv
    Mar 30, 2014 at 14:15
  • 1
    I knew about the parameter -s but didn't know about -D , living and learning :D Mar 30, 2014 at 14:18
  • 2
    If you are going to use useradd on Debian or derivatives, care needs to be taken so that UIDs/GUIDs conform with the Debian policy. This mostly only affects system users, but note that not doing this can cause issues that are serious and difficult to track down.
    – Graeme
    Mar 30, 2014 at 14:23

You are switching from one normal user (you) to another normal user, say joe, right?
The following is your shell prompt, defined in the environment variable PS1:

user@user directory $

After switching to joe, you see joe's shell prompt. And he did not configure to show anything fancy in the prompt, so only the default prompt is shown, which looks just like:


The second one is the default of the plain shell program, yours is probably the default of the linux distribution.

Try setting PS1 to the same it is in your account, it should help:

user@usersBox directory $ echo "$PS1"

and later

$ PS1="......"
joe@usersBox directory $

Replave the ...... with the value shown by the echo above.

The word after the "@" is normally the name of the computer, so I guess you gave the computer the same name as your user name during setup.
To make it less confusing in the example, I changed the computer name to "usersBox".

Maybe he removed the variant you have intentionally. But as likely, it's caused by some random minor technical issue, and he would be ok if you change it for him too, in his startup files, like ~/.bashrc or similar, depending on the kind of shell used by him.

  • Not helpful. Setting $PS1 after each call to su isn't a real solution. Mar 30, 2014 at 15:08
  • 1
    That was the variant to try it, and understand what is going on (ad in "teaching to fish"). Then I proposed to fix it permanently for him and his other user together. If it turns out that this way makes sense for the OP, I should add details on how to do it I think. I assume You were thinking of a solution where his own prompt get used by joe too, only when using the sudo? Good idea. Mar 30, 2014 at 15:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.