2

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,

BeastOfCaerbannog
  • 12,964
  • 10
  • 49
  • 77
  • 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. – vanadium Feb 15 '22 at 17:15
  • 1
    Is the ubuntu user's login shell something other than bash? Also please [edit] your question to show *how* you are switching users. – steeldriver Feb 15 '22 at 17:20
  • >"to show how you are switching users" I edited, I used `su user1` to switch user – Rayan Araujo Feb 15 '22 at 17:32
  • Does this answer your question? [How do I get a colored bash?](https://askubuntu.com/questions/517677/how-do-i-get-a-colored-bash) – Artur Meinild Feb 16 '22 at 14:28
  • 1
    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. – user68186 Feb 16 '22 at 20:34
  • 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) – pa4080 Feb 17 '22 at 13:49
  • mark this answer as answered! – Satoshi Nakamoto Feb 17 '22 at 19:48

3 Answers3

2

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.

BeastOfCaerbannog
  • 12,964
  • 10
  • 49
  • 77
1

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.

vanadium
  • 82,909
  • 6
  • 116
  • 186
  • 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` – Rayan Araujo Feb 15 '22 at 17:44
  • Then you have a different system than mine. The mv command should work everywhere. – vanadium Feb 16 '22 at 09:16
  • @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 Feb 16 '22 at 11:40
  • @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. – Ruud Helderman Feb 16 '22 at 11:40
  • @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. – vanadium Feb 16 '22 at 12:29
  • @Ruud Helderman I ran the command as root because I can't access `/home/ubuntu/.bashrc` as standard user. – Rayan Araujo Feb 16 '22 at 15:05
  • ~ 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. – vanadium Feb 16 '22 at 15:15
  • @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. – Rayan Araujo Feb 16 '22 at 15:24
  • 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. – vanadium Feb 16 '22 at 17:39
0

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.

BeastOfCaerbannog
  • 12,964
  • 10
  • 49
  • 77
Satoshi Nakamoto
  • 477
  • 4
  • 12