Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
01-14-2017, 09:45 AM
|
#1
|
LQ Guru
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342
|
change prompt when I issue su for root
I have got it to change when I issue su - but not properly and when I issue just su
it only goes to #
and the arrow keys I can only get garbage out when I use them.
Code:
userz@voider [~]\>>$su
Password:
# ls
Desktop Downloads Pictures Templates perform
Documents Music Public Videos scripts
# ^[[A
using the up arrow to reissue the last command I get that # ^[[A
I am wanting to get a better prompt when going into su with colors (after I get this to work)
something like
Quote:
root@HostName [current directory]>>#
|
but even when I add this code into .bashrc (prompt code is for test purposes)
Code:
if [[ $( id -u ) -eq 0 ]] ; then
PS1="\[\e[34m\]\u\[\e[m\]@\[\e[34m\]\H\[\e[m\] [\[\e[33m\]\W\[\e[m\]]\\>>$"
else
PS1='[\u@\h \W]\<>$ '
fi
I get this
Code:
[userz@voider ~]\<>$ su
Password:
# exit
[userz@voider ~]\<>$ su -
Password:
-sh: 16: [[: not found
\[\e[1;32m\]\u [ \[\e[0m\]\w\[\e[1;32m\] ]$ \[\e[0m\]
How do I get this to work on a system wide platform?
I already know I have to use /etc/bashrc just what is it that needs to be put inside of these files?
my system has bashrc in /etc/bash/bashrc btw
|
|
|
01-14-2017, 10:39 AM
|
#2
|
LQ Guru
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 8,419
|
Quote:
Originally Posted by Beyond Linux From Scratch
# Setup a red prompt for root and a green one for users.
NORMAL="\[\e[0m\]"
RED="\[\e[1;31m\]"
GREEN="\[\e[1;32m\]"
if [[ $EUID == 0 ]] ; then
PS1="$RED\u [ $NORMAL\w$RED ]# $NORMAL"
else
PS1="$GREEN\u [ $NORMAL\w$GREEN ]\$ $NORMAL"
fi
|
They recommend doing this in /etc/profile. The root user often has history turned off for security reasons, which may be why your arrow keys don't work.
|
|
|
01-14-2017, 10:55 AM
|
#3
|
LQ Veteran
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Rep: 
|
Before you edit...
Your bash_history arrow keys don't work because
gets you get root without root's environment, were
you gets you root with root's environment.
Code:
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[01;34m\] \w \$\[\033[00m\] '
in both user and root .bashrc files. Source 'em or logout and back in.
Gets you a red prompt for root, but you have to use
to invoke it.
Last edited by Habitual; 01-14-2017 at 10:59 AM.
|
|
1 members found this post helpful.
|
01-14-2017, 11:54 AM
|
#4
|
LQ Guru
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342
Original Poster
|
Quote:
Originally Posted by hazel
They recommend doing this in /etc/profile. The root user often has history turned off for security reasons, which may be why your arrow keys don't work.
|
haha actaully tried that one and it didn't work -- lead me to having to post a how to in here. thanks!
|
|
|
01-14-2017, 11:54 AM
|
#5
|
LQ Guru
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342
Original Poster
|
Quote:
Originally Posted by Habitual
Before you edit...
Your bash_history arrow keys don't work because
gets you get root without root's environment, were
you gets you root with root's environment.
Code:
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[01;34m\] \w \$\[\033[00m\] '
in both user and root .bashrc files. Source 'em or logout and back in.
Gets you a red prompt for root, but you have to use
to invoke it.
|
seen that one on the net, didn't understand it. plus it is saying debain when I am NOT running Debain .. soo it too may not work
|
|
|
01-14-2017, 12:46 PM
|
#6
|
LQ Guru
Registered: Sep 2009
Location: Perth
Distribution: Arch
Posts: 10,039
|
Try using single quotes instead of double, like you did for your user prompt.
|
|
|
01-14-2017, 12:58 PM
|
#7
|
LQ Guru
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342
Original Poster
|
Quote:
Originally Posted by grail
Try using single quotes instead of double, like you did for your user prompt.
|
OK --
|
|
|
01-14-2017, 01:12 PM
|
#8
|
LQ Guru
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342
Original Poster
|
OK this is in order. System bashrc, root .bashrc, userx (me) .bashrc
Code:
[userx@voider.org ~]$ sudo cat /etc/bash/bashrc
# /etc/bash/bashrc
# Do not edit this file.
# Place your readable configs in /etc/bash/bashrc.d/*.sh
if [[ $- != *i* ]] ; then
# Shell is non-interactive. Be done now!
return
fi
if [ -d /etc/bash/bashrc.d/ ]; then
for f in /etc/bash/bashrc.d/*.sh; do
[ -r "$f" ] && . "$f"
done
unset f
fi
if [ -f /usr/bin/neofetch ]; then neofetch; fi
# Setup a red prompt for root and a green one for users.
NORMAL='\[\e[0m\]'
RED='\[\e[1;31m\]'
GREEN='\[\e[1;32m\]'
if [[ $EUID == 0 ]] ; then
PS1='$RED\u [ $NORMAL\w$RED ]# $NORMAL'
else
PS1='$GREEN\u [ $NORMAL\w$GREEN ]\$ $NORMAL'
fi
Code:
[userx@voider.org ~]$ sudo cat /root/.bashrc
# .bashrc
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
alias ls='ls --color=auto'
PS1='[\u@\H \W]\$ '
Code:
[userx@voider.org ~]$ cat .bashrc
# .bashrc
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
alias ls='ls --color=auto'
PS1='[\u@\H \W]\$ '
that bold line works as a system wide command, but that change prompt does not.
this isn't helping
Code:
[userx@voider.org ~]$ echo $EUID
1000
[userx@voider.org ~]$ su
Password:
# echo $EUID
# su -
# echo $EUID
# echo $UID
# exit
# echo $UID
#
exit to get me back from su - to just su to echo $UID. both are coming up blank - null - empty
now when I change that test in /etc/bash/bashrc to this
Code:
# Setup a red prompt for root and a green one for users.
NORMAL='\[\e[0m\]'
RED='\[\e[1;31m\]'
GREEN='\[\e[1;32m\]'
#if [[ $EUID == 0 ]] ; then
if [[ $(id -u) -eq 0 ]] ; then
PS1='$RED\u [ $NORMAL\w$RED ]# $NORMAL'
else
PS1='$GREEN\u [ $NORMAL\w$GREEN ]\$ $NORMAL'
fi
then run this
Code:
[userx@voider.org ~]$ su
Password:
# id
uid=0(root) gid=0(root) groups=0(root)
# id -u
0
# su -
# id -u
0
#
still nothing. all I am getting is this prompt.
Code:
[userx@voider.org ~]$ su
Password:
#
Last edited by BW-userx; 01-14-2017 at 01:21 PM.
|
|
|
01-14-2017, 01:34 PM
|
#9
|
LQ Guru
Registered: Sep 2009
Location: Perth
Distribution: Arch
Posts: 10,039
|
hmmm ... seems I was not clear  As per your original post, without the addition of variables, use single quotes:
Code:
if [[ $( id -u ) -eq 0 ]] ; then
PS1="\[\e[34m\]\u\[\e[m\]@\[\e[34m\]\H\[\e[m\] [\[\e[33m\]\W\[\e[m\]]\\>>$"
else
PS1='[\u@\h \W]\<>$ '
fi
# becomes
if [[ $( id -u ) -eq 0 ]] ; then
PS1='\[\e[34m\]\u\[\e[m\]@\[\e[34m\]\H\[\e[m\] [\[\e[33m\]\W\[\e[m\]]\\>>$ '
else
PS1='[\u@\h \W]\<>$ '
fi
When using double quotes you need to be aware of how many escapes you need in certain places or you get unusual responses.
This will not affect simple su, as was pointed out earlier you are not entering root's environment fully so this file you have changed will not be sourced.
|
|
|
01-14-2017, 02:56 PM
|
#10
|
LQ Guru
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342
Original Poster
|
Quote:
Originally Posted by grail
hmmm ... seems I was not clear  As per your original post, without the addition of variables, use single quotes:
Code:
if [[ $( id -u ) -eq 0 ]] ; then
PS1="\[\e[34m\]\u\[\e[m\]@\[\e[34m\]\H\[\e[m\] [\[\e[33m\]\W\[\e[m\]]\\>>$"
else
PS1='[\u@\h \W]\<>$ '
fi
# becomes
if [[ $( id -u ) -eq 0 ]] ; then
PS1='\[\e[34m\]\u\[\e[m\]@\[\e[34m\]\H\[\e[m\] [\[\e[33m\]\W\[\e[m\]]\\>>$ '
else
PS1='[\u@\h \W]\<>$ '
fi
When using double quotes you need to be aware of how many escapes you need in certain places or you get unusual responses.
This will not affect simple su, as was pointed out earlier you are not entering root's environment fully so this file you have changed will not be sourced.
|
sorry - I wiped my system and re-installed and well I figured I'd go from that linux from scratch in the system bashrc which is where this code should go to get system wide usage so I do not have to deal with my user .bashrc in this matter, yes?
if you look cose enough you'd see I replaced that " " with ' ' within the if else it is just the prompt code that is different, still regardless if I use
Code:
if [[ $( id -u ) -eq 0 ]] ; then or
if [[ $EUID == 0 ]] ; then
it does not work.
look see
Code:
if [[ $(id -u) -eq 0 ]] ; then
PS1='$RED\u [ $NORMAL\w$RED ]# $NORMAL'
else
PS1='$GREEN\u [ $NORMAL\w$GREEN ]\$ $NORMAL'
fi
single quotes are being used. still no go.
look see
Code:
GNU nano 2.7.4 File: /etc/bash/bashrc
# /etc/bash/bashrc
# Do not edit this file.
# Place your readable configs in /etc/bash/bashrc.d/*.sh
if [[ $- != *i* ]] ; then
# Shell is non-interactive. Be done now!
return
fi
if [ -d /etc/bash/bashrc.d/ ]; then
for f in /etc/bash/bashrc.d/*.sh; do
[ -r "$f" ] && . "$f"
done
unset f
fi
if [ -f /usr/bin/neofetch ]; then neofetch; fi
if [[ $( id -u ) -eq 0 ]] ; then
PS1='\[\e[34m\]\u\[\e[m\]@\[\e[34m\]\H\[\e[m\]
[\[\e[33m\]\W\[\e[m\]]\\>>$ '
else
PS1='[\u@\h \W]\<>$ '
fi
I still get this
Code:
[userx@voider.org ~]$ su
Password:
# su -
#
I think it is that the terminal starts out user, when it is still running and gets changed to root by su it does not look into that /etc/bash/basrc file again because it is already running(?) so it does not get sourced again?
Last edited by BW-userx; 01-14-2017 at 03:15 PM.
|
|
|
01-14-2017, 03:32 PM
|
#11
|
LQ Veteran
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Rep: 
|
Quote:
Originally Posted by BW-userx
seen that one on the net, didn't understand it. plus it is saying debain when I am NOT running Debain .. soo it too may not work
|
You have to understand it to try it?
I ran that on Slackware.
I've had it for 8 years.
|
|
|
01-14-2017, 03:43 PM
|
#12
|
LQ Guru
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342
Original Poster
|
Quote:
Originally Posted by Habitual
You have to understand it to try it?
I ran that on Slackware.
I've had it for 8 years.
|
damn ... figures now that I am looking for that one post on this Debian_Chroot ... I cannot find it. SO i just stuck that in my if else in system bashrc it did nothing, so I stuck it in my ~/.bashrc and still I get nothing when changing from user to su (root) just the pound sign #
|
|
|
01-14-2017, 06:41 PM
|
#13
|
LQ Guru
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342
Original Poster
|
Code:
[userx@voider.org]:
[~]>>$ ps -p $$
Thank you
PID TTY TIME CMD
19323 pts/2 00:00:00 bash
[userx@voider.org]:
[~]>>$ su
Password:
# ps -p $$
PID TTY TIME CMD
15778 pts/2 00:00:00 sh
# su -
# ps -p $$
PID TTY TIME CMD
15947 pts/2 00:00:00 sh
# chsh -s /bin/bash
Changing shell for root.
Shell changed.
#
Now it is working.. just need to tweek the prompt
[root@voider.org userx]2
Now I got it.. failed to check shell for root ... always is something simple over looked item.
|
|
|
All times are GMT -5. The time now is 04:41 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|