SlackwareThis Forum is for the discussion of Slackware Linux.
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.
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.
I would like to create an identification for root and intend to use PS1 color customisation { PS1="\[\e[41;30m\][\h|\w ]\[\e[0m\]} . But, it's important to get a contrast during ssh sessions on Cisco routers and remote server machines.
We know that ssh forces Login and Interative Shell Invocation. Then where have I create my PS1 set in a /etc/.bashrc, /etc/.bash_profile or another directory and see a different color prompt during "su" root login?
When going from one Slackware 14.1 box to the other via ssh, you get login bash shell, and so you want the stanza in .bash_profile on the remote host. Ditto for su - on a localhost. But when using su (no -) on a localhost, you get the interactive bash shell, and you want the stanza in .bashrc.
I actually use color coding, and I prefer it in .bash_profile only. This enables colors for ssh and su -, but not su. Since I don't use su for anything, this is just what I need.
I have this in my root and all other users .bashrc on the remote machines :-
Code:
if ps ax | grep sshd: | grep -v grep &>/dev/null; then #test if this is a remote login
PS1='\[\033[1;34m\][\u\[\033[1;33m\]@\h\[\033[1;34m\]:\w]\$ \[\033[0m\]'
else
PS1='\[\033[1;34m\][\u:\w]\$ \[\033[0m\]'
fi
export PS1
Works on my little home network. Not too sure if this would work in your situation though.
Good Evening, slackers!!!
I would like to create an identification for root and intend to use PS1 color customisation { PS1="\[\e[41;30m\][\h|\w ]\[\e[0m\]} . But, it's important to get a contrast during ssh sessions on Cisco routers and remote server machines.
We know that ssh forces Login and Interative Shell Invocation. Then where have I create my PS1 set in a /etc/.bashrc, /etc/.bash_profile or another directory and see a different color prompt during "su" root login?
This isn't just for Slackware, since PS1 and prompts are pretty universal. I settled on one a few years ago, which I like:
This way, a 'normal' user will be in cyan, the hostname will be white, and the current directory is in yellow. When you run "sudo -s", you will get the root user ID in red...a good indication that you're doing something as root.
Shove those in .bashrc and enjoy. You can also just use the SUDO_PS1 as a standard PS1 in your root .bashrc.
I have this in my root and all other users .bashrc on the remote machines :-
Code:
if ps ax | grep sshd: | grep -v grep &>/dev/null; then #test if this is a remote login
PS1='\[\033[1;34m\][\u\[\033[1;33m\]@\h\[\033[1;34m\]:\w]\$ \[\033[0m\]'
else
PS1='\[\033[1;34m\][\u:\w]\$ \[\033[0m\]'
fi
export PS1
Works on my little home network. Not too sure if this would work in your situation though.
I am like a coil!!!
1)Do you have a local lan or a ssh remote acess using ISP service? After that, can you see yours PS1 setting "A" [user@hostname:~]$ in another remote machine "B" differ you among a lot of shells?
2)Do you do both root and normal user's .bashrc and .bash_profile?
I am like a coil!!!
1)Do you have a local lan or a ssh remote acess using ISP service? After that, can you see yours PS1 setting "A" [user@hostname:~]$ in another remote machine "B" differ you among a lot of shells?
2)Do you do both root and normal user's .bashrc and .bash_profile?
1)This is my home network, that is a LAN with my desktop machine and laptop. Both running Slackware64 current. With the second part of the question do you mean "Do the different prompts standout from each other?". If this is what you mean, then it does for me. YMMV depending on the background colour of your terminal which can be adjusted very easily.
2) I have .bashrc and .bash_profile for all users including root and on both machines so as I can ssh from desktop to laptop or vice versa.
There is 1 disadvantage with this if you ssh into a remote machine then the remote machine will also display the same prompt for local users. I have only just noticed this. If this is to be used on a server environment this would affect everybody who ssh'd into the server as well as users logging in locally on the server. It works for me as I'm the only user on my little home network.
...adjusting PS1 strings as desired. Still works when you've su'd or sudo'd too.
It even works if you ssh user@localhost, unlike the ps ax | grep sshd: approach, which can't differenciate one session from another.
There is 1 disadvantage with this if you ssh into a remote machine then the remote machine will also display the same prompt for local users. I have only just noticed this. If this is to be used on a server environment this would affect everybody who ssh'd into the server as well as users logging in locally on the server. It works for me as I'm the only user on my little home network.
My apologies for raising your hopes.
I'm going ahead looking for my problem!
But yours disadvantage occurrence... I think it's an usual bash behaviour so it attempts to determine when it is being run with its standard input connected to a network connection, as when executed by the remote shell daemon like a secure shell daemon sshd. In this case it reads and executes commands from ~/.bashrc, if that file exists and is readable.
...adjusting PS1 strings as desired. Still works when you've su'd or sudo'd too.
It even works if you ssh user@localhost, unlike the ps ax | grep sshd: approach, which can't differenciate one session from another.
Aha! This is a far more elegant and robust solution than mine. I still like to have different colours and style of prompts between local and remote prompts so have modified your solution thus:-
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.