4

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'
fixer1234
  • 28,064
wim
  • 3,327

2 Answers2

7
$ ssh ::1 -t "export PS1='Sending a custom prompt \w \$ '; exec sh"
Password: 
Sending a custom prompt ~ $ exit
Connection to ::1 closed.
Eroen
  • 6,561
0

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.