Score:2

Terminal won't display colors for non-root users

vn flag

When I'm logged in as root, I can display colors, but not when I switch to another user.

The command ls --color=auto only displays colors once when logged as normal user.

I searched a lot and did a couple things other users recommended like:

echo $TERM

which returns:

xterm-256color

I also changed the .bashrc file in /home/ubuntu as root, I uncommented the #force_color_prompt=yes line to force_color_prompt=yes, but then I switched the normal user su steam and tried ls and everything is still white.

Here is my prompt when I'm logged as root and when I switch user:

My prompt when I'm logged as root and when I switch user

I saw that this system has only 1 directory inside the /home/ directory (it's home/ubuntu), which confuses me because I thought it was supposed to have one directory for each user. I suspect that this must be causing my problem: the root user shows colored prompt, but the standard user doesn't, because the standard user can't access the .bashrc file inside the home/ubuntu directory,

vanadium avatar
cn flag
You probably messed up with your .bashrc file in some way, because it is there that the color of the prompt is set, and the alias ls --color is defined by default.
hr flag
Is the ubuntu user's login shell something other than bash? Also please [edit] your question to show *how* you are switching users.
Rayan Araujo avatar
vn flag
>"to show how you are switching users" I edited, I used `su user1` to switch user
Artur Meinild avatar
vn flag
Does this answer your question? [How do I get a colored bash?](https://askubuntu.com/questions/517677/how-do-i-get-a-colored-bash)
ar flag
Please don't put SOLVED in the question title in this question answer site. You should accept the answer that answered your question. That may be your own answer. You accept an answer by clicking on the gray check mark next to the answer and turn it green ✅. This marks the problem solved and helps others.
pa4080 avatar
cn flag
Does this answer your question? [At what point is the ~/.bashrc file created?](https://askubuntu.com/questions/971836/at-what-point-is-the-bashrc-file-created) - based on the OP self [answer](https://askubuntu.com/a/1393302/566421)
Satoshi Nakamoto avatar
lc flag
mark this answer as answered!
Score:1
cn flag

This is typically set in a default .bashrc file. You can restore your .bashrc file to a factory default one:

cp --backup=t /etc/skel/.bashrc ~

This command first creates a backup of your current .bashrc before overwriting it with a default one. If you need to do this for a different user, then supply the full path of the target user's home directory, and change the owner of the copy to the target user.

If you are proficient with .bashrc, you may instead inspect the file /etc/skel/.bashrc to learn on how to implement this in your personal file.

Rayan Araujo avatar
vn flag
I did this and nothing happened, no `.bashrc.old` was created and it did not restored the original one to default. I think its good to mention that my `.bashrc` is inside `/home/ubuntu` and not only `/home`
vanadium avatar
cn flag
Then you have a different system than mine. The mv command should work everywhere.
Ruud Helderman avatar
in flag
@vanadium Nitpick on the backup: I'd be more in favor of `cp --backup=t /etc/skel/.bashrc ~` because (1) it's short and self-explanatory, (2) it doesn't trash the backup when run twice, (3) it saves you the trouble of having to restore the backup in case your system doesn't have a file `/etc/skel/.bashrc`.
Ruud Helderman avatar
in flag
@RayanAraujo Assuming `user1` is the user having the problem, you should either run vanadium's command while logged in as `user1`, or replace every `~` with `~user1` in the command. I'm guessing you ran the command as root, meaning you changed root's `bashrc`; you may want to restore that backup first.
vanadium avatar
cn flag
@RuudHelderman thanks for this useful tip, which I added to the answer. I added some info to do this for other users, but it is out of the scope to explain that needs to be done with sudo etc... especially since OP tells he is logged in as a user.
Rayan Araujo avatar
vn flag
@Ruud Helderman I ran the command as root because I can't access `/home/ubuntu/.bashrc` as standard user.
vanadium avatar
cn flag
~ exands to the home folder of the *current* user. If you are not logged in as that other user, then you need to explicitly specify the paths and moreover chown the resulting copy to that user. Added this to the answer. However, in your question you indicate you switched to another user. Now, you say you cannot access his folder. So you may need to edit your question to clarify.
Rayan Araujo avatar
vn flag
@vanadium I just edited. I have the `steam` user (same as the `user1`, I was using as example) and when I'm logged as this user I can't access the `/home/` folder because it doesn't has enough permissions.
vanadium avatar
cn flag
steam user probably is not intended as an account to log in to. Perhaps open a new question and tell what you really want to achieve. Likely, there is no need to act as the user steam.
Score:1
vn flag

I think I figured out what the problem was. When I was setting up my system, I created a user with useradd, which just creates an user without any home folder; you have to do it manually.

I created a test user with the command adduser and it's kinda different, but it created its own directory, and, when I disconnected and connected again with ssh test@<ip address>, the prompt showed all colors normally.

user1 was sharing the same directory as the root, but it hadn't any permission to access the /home/ directory where .bashrc is located.

Score:0
lc flag

You edited your .bashrc as root and you need to change the ownership back to its original user. Try:

chown [OPTIONS] USER[:GROUP] FILE(s)

By the way, don't do that as root, go back to a normal user and use that command with sudo as, for example:

sudo chown jimmy .bashrc

If that didn't work you can try what this user suggested. If this also doesn't work, maybe you're having problems when listing with ls. In this case, try this instead.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.