CentOS 7.7automatically going to bash mode

General support questions
Post Reply
deep.dey
Posts: 5
Joined: 2019/11/11 07:00:43
Location: Kolkata
Contact:

CentOS 7.7automatically going to bash mode

Post by deep.dey » 2019/11/11 07:08:53

Why is my CentOS 7.7 automatically going to bash mode whenever I am trying to login as root?
Whenever I am trying to login as root ,its going to bash mode.
Attachments
centos.png
centos.png (2.99 KiB) Viewed 3609 times

User avatar
TrevorH
Site Admin
Posts: 33202
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: CentOS 7.7automatically going to bash mode

Post by TrevorH » 2019/11/11 10:44:41

That's working as designed. You are sitting at a root command prompt. You should be using su - not just su though.

The portion of the command prompt you are looking at is provided by the environment variable "PS1". It's not set so bash populates it with something and its authors choice "bash-$bashversion". Why it's not set is another question...
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

deep.dey
Posts: 5
Joined: 2019/11/11 07:00:43
Location: Kolkata
Contact:

Re: CentOS 7.7automatically going to bash mode

Post by deep.dey » 2019/11/12 12:02:26

I just installed CentOS 2 days ago. I haven't installed anything on it yet. Everything is working fine but whenever I am trying to login as root its going to bash mode. What should I do now ?

User avatar
TrevorH
Site Admin
Posts: 33202
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: CentOS 7.7automatically going to bash mode

Post by TrevorH » 2019/11/12 12:08:46

All that is is your command prompt. It's not in "bash mode". You use bash as your shell so that is your command prompt. Without bash you wouldn't be looking at the terminal window at all, it would have closed.
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

deep.dey
Posts: 5
Joined: 2019/11/11 07:00:43
Location: Kolkata
Contact:

Re: CentOS 7.7automatically going to bash mode

Post by deep.dey » 2019/11/12 12:58:11

I understood everything you said. Please check my attached image for details.
I am trying to login using su command. After login its showing bash-4.2#..It should show me root@localhost ~]$
Attachments
bash.png
bash.png (50.38 KiB) Viewed 3544 times

User avatar
jlehtone
Posts: 4523
Joined: 2007/12/11 08:17:33
Location: Finland

Re: CentOS 7.7automatically going to bash mode

Post by jlehtone » 2019/11/12 13:58:24

This is on CentOS 7 machine. My own PS1 is custom. Both 'su' and 'su -' redefine PS1:

Code: Select all

fubar:2:~$ echo $PS1
\h:\l:\w\$
fubar:2:~$ su
Password: 
[root@fubar jlehtone]# echo $PS1
[\u@\h \W]\$
[root@fubar jlehtone]# exit
exit
fubar:2:~$ su -
Password: 
Last login: Sun Feb 30 00:00:01 GMT 1970 on pts/2
[root@fubar ~]# echo $PS1
[\u@\h \W]\$
The redefinition occurs in /etc/bashrc and by comments there any host-wide customizations should be added via shell script in /etc/profile.d/

I have seen the "undefined PS1" (i.e. the "bash-${bashversion}# " to occur when bash init fails. It does not look like you have such failure, so first guess is that you have modified configuration somehow.

What do these show?

Code: Select all

rpm -V setup
rpm -qf /etc/profile.d/*.sh
PS. Please post textual information as text. Bitmaps are barbaric (IMHO).

deep.dey
Posts: 5
Joined: 2019/11/11 07:00:43
Location: Kolkata
Contact:

Re: CentOS 7.7automatically going to bash mode

Post by deep.dey » 2019/11/13 05:26:41

First command rpm -V setup is not showing me anything.
Second command showing me this (check attached image)
Attachments
cent.png
cent.png (11.47 KiB) Viewed 3511 times

desertcat
Posts: 843
Joined: 2014/08/07 02:17:29
Location: Tucson, AZ

Re: CentOS 7.7automatically going to bash mode

Post by desertcat » 2019/11/14 09:40:45

deep.dey wrote:
2019/11/12 12:58:11
I understood everything you said. Please check my attached image for details.
I am trying to login using su command. After login its showing bash-4.2#..It should show me root@localhost ~]$
Hummmmm. There are two things that pop out at me. Look at you two images. In the second one it says: ikf@speedtest:~$

Now look at at the first image, it says: [crm@localhost ~] $

While I don't know this for sure the fact that the machine is referred to as "localhost" rather than a specific name --ie speedtest -- simply drops the prompt down to the simplest bash prompt.

If this is REALLY driving you CRAZY there are a couple of easy things you could do.

1) Give the machine a name. This can be set in /etc/hostname. Use a file browser such a Midnight Commander (mc) to edit the file and then save the file with your new machine name; alternately use a text editor such as sublime, vi, vim, create your machine name, and then save it. Then re-boot the machine to mak it take effect.

2) Again using something like mc or sublime go to /etc/bashrc and find the line that begins:

[ "$PS1" = "\\s-\\v\\\$ " ] && PS1="

where PS1="[\u@\h:\l \W] \\$ "

...or which ever variables you chose. For example my prompt looks like this:


[ "$PS1" = "\\s-\\v\\\$ " ] && PS1="\[\033[1;32m\][\[\033[1;33m\]\u\[\033[1;36m\]@\h\[\033[1;31m\]\w\[\033[1;32m\]]\[\033[1;35m\]/>\[\033[1;37m\]"

The highlighted parts are the variables, just so you can see where those PS1 variables I used are located.

After you have modified your prompt save it. Kill the konsole and restart it to see your new prompt.

A third thing to try is go to a machine that you know has a working prompt. ie. say "speedtest". Using sneakernet copy the file /etc/bashrc, and again using sneakernet take the copied /etc/bashrc back to your machine. Go into your machine and find /etc/bashrc and rename it to say /etc/bashrc.old; having done that take your copied /etc/bashrc and copy it into place; now reboot your machine, and try your su, Passoword, etc. and see if you still get the bash-4.2#. If you don't then your bashrc file may have gotten scrambled, if you do, then it may be one of the things I've guess at.

Now if you REALLY want to go hog wild and design a REAL CUSTOM PROMPT I'd install zsh -- sort of like bash, but on steroids.

Best of luck.

D'Cat

Post Reply