Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
How to prevent forgeting you're SSH'ed
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Duplicate Threads
View previous topic :: View next topic  
Author Message
RedBeard0531
Guru
Guru


Joined: 21 Sep 2002
Posts: 415
Location: maryland

PostPosted: Fri Jun 27, 2003 11:51 am    Post subject: How to prevent forgeting you're SSH'ed Reply with quote

Ive seen several posts talking about how people forget there on a box several thousand miles away, when they do something like mkfs, or shutdown -5. While I use this on my computer downstaris, it is still annoying it I do anything stupid, becuase it holds my media.

In /ets/profile, change this number in your PS1 variable to something differant on each machine.
PS1="\\[\\033[01;31m\\]\\h \\[\\033[01;34m\\]\\W \\\$ \\[\\033[00m\\]"

This will cause the hostname to appear a differant color. Here is a partial list of colors, if you want more, try them out.
29=grey
30=white
31=red
32=green
33=yellow
34=blue
_________________
OH MY GOD! Kenny just killed Kenny!
That Basterd!


Last edited by RedBeard0531 on Fri Jun 27, 2003 8:54 pm; edited 1 time in total
Back to top
View user's profile Send private message
GenKiller
n00b
n00b


Joined: 04 Mar 2003
Posts: 66
Location: United States of America

PostPosted: Fri Jun 27, 2003 8:08 pm    Post subject: Reply with quote

Are all those "B's" in your title really necessary? Or was that a typo?

This is a good tip, but perhaps this could be expanded into just changing the PS1 variable when someone ssh's in, and only then. That way, people could keep their current setup when they were physically at the machine (root=red user=green), and have it change when they are SSH'd in.

Just a thought, I don't know off the top of my head how to impliment it.
_________________
http://www.digital-drip.com
Back to top
View user's profile Send private message
RedBeard0531
Guru
Guru


Joined: 21 Sep 2002
Posts: 415
Location: maryland

PostPosted: Fri Jun 27, 2003 8:55 pm    Post subject: Reply with quote

GenKiller wrote:
Are all those "B's" in your title really necessary? Or was that a typo?


Im missing the nubby thing covering the mouse on my lappy, so Im always resting on the b botton. Thnx for pointen that out.
_________________
OH MY GOD! Kenny just killed Kenny!
That Basterd!
Back to top
View user's profile Send private message
GenKiller
n00b
n00b


Joined: 04 Mar 2003
Posts: 66
Location: United States of America

PostPosted: Fri Jun 27, 2003 10:58 pm    Post subject: Reply with quote

RedBeard0531 wrote:
Im missing the nubby thing covering the mouse on my lappy, so Im always resting on the b b[u]tton. Thnx for point[ing] that out.


I thought it was probably something like that :) I can't begin to tell you how many programming typos I make because of similar reasons :oops:
_________________
http://www.digital-drip.com
Back to top
View user's profile Send private message
cleber
n00b
n00b


Joined: 05 Aug 2003
Posts: 74
Location: São Paulo - Brazil

PostPosted: Tue Aug 05, 2003 7:40 am    Post subject: How to prevent forgeting you're SSH'ed Reply with quote

I have a similar problem, so I got this .bashrc that helps me out.

Place this code inside your ~/.bashrc in every machine you have a login.
It changes $PS1if I'm on SSH (or telner, etc).

Code:

#In ~/.bashrc
THIS_TTY=tty`ps aux | grep $$ | grep bash | awk '{ print $7 }'`
SESS_SRC=`who | grep $THIS_TTY | awk '{ print $6 }'`

SSH_FLAG=0
SSH_IP=`echo $SSH_CLIENT | awk '{ print $1 }'`
if [ $SSH_IP ] ; then
  SSH_FLAG=1
fi
SSH2_IP=`echo $SSH2_CLIENT | awk '{ print $1 }'`
if [ $SSH2_IP ] ; then
  SSH_FLAG=1
fi
if [ $SSH_FLAG -eq 1 ] ; then
  CONN=ssh
elif [ -z $SESS_SRC ] ; then
  CONN=lcl
elif [ $SESS_SRC = "(:0.0)" -o $SESS_SRC = "" ] ; then
  CONN=lcl
else
  CONN=tel
fi

# Okay...Now who we be?
if [ `/usr/bin/whoami` = "root" ] ; then
  USR=priv
else
  USR=nopriv
fi

#Set some prompts...
if [ $CONN = lcl -a $USR = nopriv ] ; then
  PS1="[\u@\h \w]\\$ "
elif [ $CONN = lcl -a $USR = priv ] ; then
  PS1="\[\033[01;31m\][\w]\\$\[\033[00m\] "
elif [ $CONN = tel -a $USR = nopriv ] ; then
  PS1="\[\033[01;34m\][\u@\h \w]\\$\[\033[00m\] "
elif [ $CONN = tel -a $USR = priv ] ; then
  PS1="\[\033[01;30m\][\u@\h \w]\\$\[\033[00m\] "
elif [ $CONN = ssh -a $USR = nopriv ] ; then
  PS1="\[\033[01;30m\][\u@\h \w]\\$\[\033[00m\] "
elif [ $CONN = ssh -a $USR = priv ] ; then
  PS1="\[\033[01;35m\][\u@\h \w]\\$\[\033[00m\] "
else
  PS1="[\u@\h \w]\\$ "
fi


PS: This code is not mine!
PS2: First post! ;)
Back to top
View user's profile Send private message
GenKiller
n00b
n00b


Joined: 04 Mar 2003
Posts: 66
Location: United States of America

PostPosted: Tue Aug 05, 2003 6:40 pm    Post subject: Re: How to prevent forgeting you're SSH'ed Reply with quote

cleber wrote:
I have a similar problem, so I got this .bashrc that helps me out.

Place this code inside your ~/.bashrc in every machine you have a login.
It changes $PS1if I'm on SSH (or telner, etc).

PS: This code is not mine!
PS2: First post! ;)


Great first post cleber! All I modified was the colors, and took out the first two if statements under the "setting terms" section, so that Gentoo's default's still appear.

Welcome to the Forums :)
_________________
http://www.digital-drip.com
Back to top
View user's profile Send private message
pjp
Administrator
Administrator


Joined: 16 Apr 2002
Posts: 20067

PostPosted: Sun Sep 21, 2003 6:31 pm    Post subject: Reply with quote

See Extra informative Bash prompt.
_________________
Quis separabit? Quo animo?
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Duplicate Threads All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum