Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to be able to set a custom prompt (to help with automating jobs, the prompt should be something I can reliably detect). I found I am able to set the prompt remotely, like this:

wim@wim-acer:~$ ssh guest@192.168.1.124 -i ~/.ssh/guest_nopassphrase 
~ # echo $PS1
\w \$
~ # PS1='Setting a custom prompt \w \$ '
Setting a custom prompt ~ # exit
Connection to 192.168.1.124 closed.

Is there a way to do it in one shot in the first place, by using a different ssh command? The suggestion I tried in the answer of a related question didn't work for me:

wim@wim-acer:~$ ssh guest@192.168.1.124 -i ~/.ssh/guest_nopassphrase -t "PS1='Sending a custom prompt \w \$ '; exec sh"
~ # set
HOME='/var/tmp'
IFS='   
'
LOGNAME='guest'
PATH='/sbin:/usr/sbin:/bin:/usr/bin'
PPID='1039'
PS1='\w \$ '
PS2='> '
PS4='+ '
PWD=''
SHELL='/bin/sh'
TERM='xterm'
USER='guest'
share|improve this question
    
Not even if you add export just in front of PS1=? – Eroen Mar 13 '12 at 5:56
    
ah, your suggestion worked :) if you add it as an answer, i can accept it tomorrow. – wim Mar 13 '12 at 6:03
    
I just have it changed in my .bashrc file so I know what I'm on at a glance by what info is shown. – Rob Mar 13 '12 at 6:18
    
@Rob do you mean the .bashrc file on the remote machine? if so, that is not an option for me – wim Mar 13 '12 at 6:36
up vote 4 down vote accepted
$ ssh ::1 -t "export PS1='Sending a custom prompt \w \$ '; exec sh"
Password: 
Sending a custom prompt ~ $ exit
Connection to ::1 closed.
share|improve this answer

Did you consider editing the .bashrc file on the remote host?

A simple:

export PS1='Setting a custom prompt \w \$ '

at the end of ~/.bashrc on the remote host will make sure the prompt is changed each time you log in. It will obviously affect any other users of the account too.

share|improve this answer
1  
Thanks, I considered it - but I need to do it on hundreds of dumb boxes, so it is preferably to be able to send it on the fly rather than set it up on each one. – wim Mar 13 '12 at 6:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .