I would like to configure my PuTTY session in such a way that I could login to a remote host, and (a) start bash (b) change the PS1 variable (prompt content) (c) continue work in the session as normal.

I tried:

  1. Connection -> Data -> Environment variables [does not work; session looks as if (b) had not been executed] AND
  2. Connection -> SSH -> Remote command: PS1="some stuff" [the window with the session opens for a fraction of sec, and then it closes]

Any ideas? I had had a look to some similar questions in the forum, but did not find anything helpful.

More generally: I log in into a host where many users log in as a single user, and thus they all share the 'settings' of the single user. I look for a method of forcing PuTTY into changing some of these settings temporarily (i.e., such that they would be time limited to the session that I open using PuTTY). Sort of running personal version of .bashrc within the session. Hope this makes sense.


The target server needs to be configured to accept setting environment variables for the 1st option to work. The second is actually working fine, the problem is that it is designed to mimic

ssh user@foo command

which will just connect, run command and exit. You can have it remain open by giving it command; bash but that won't work for setting your variables sice a new shell will be started after the variable has been set.

So, short of having root access to the server so that you can enable the setting of environmental variables, the only way I can think of for you to do this is to edit ~/.bashrc the server and define your PS1 there. Add this line to ~/.bashrc:

PS1="some stuff"

Now, every time you log into that server, the prompt will be set for you.

Another way to do this would be to use a different rcfile for your bash session. Create a new file with these lines:

source /etc/profile
source ~/.bashrc
PS1='some stuff'

Save it as, for example, ~/.myps1, then in your putty settings, set the command to run on the remote server to:

bash --rcfile ~/.myps1

This will open a new shell session o the remote server and read in the file above which first reads .bashrc and then sets PS1.

  • I added a note to the original question. Problem is that the .bashrc is shared among all the users who log in, and I cannot modify it... I could create a personalized .bashrc-my, but then I still don't know how could I call it when logging in with PuTTY. – Simon Righley Jan 29 '14 at 17:42
  • @SimonRighley OK, can you set the server to allow setting of env variables as described in the post I linked to? You could always just add an alias to the shared .bashrc: alias ps1="PS1='some stuff'" and then run the alias each time you log in. – terdon Jan 29 '14 at 17:54
  • @SimonRighley see updated answer for another solution. – terdon Jan 29 '14 at 18:04
  • Fantastic! That did the trick :) Thank you so much! Spent so much time trying to figure this out... Can I now define all sort of aliases, variables and what not in the ~/.myps1 (I called it ~/.bashrc-my_name), and the protocol you described will respect the settings from the default .bashrc, and after that (on top of it?) it will read in all that I'll define in bashrc-my_name? – Simon Righley Jan 29 '14 at 18:17
  • 1
    @SimonRighley yup. As long as you source the global .bashrc first, anything you do after that will supersede any settings you have in .bashrc. Settings in .bashrc that are not overwritten by commands in .bashrc-my_name will persist. – terdon Jan 29 '14 at 18:18

Try setting the remote command to something like export PS1='foo'; /usr/bin/bash... that should spawn a bash session after setting PS1.

  • That won't because PS1 will be reset when the new shell is started since PS1 is normally set in one of the global config files. – terdon Jan 29 '14 at 17:58
  • It worked in my environment, but everyone's setup is potentially different. For reference I tested against HP-UX, which is admittedly not very common anymore. – BowlesCR Jan 29 '14 at 18:02
  • I report that, unfortunately, it does not help. The PS1 value is back to the default one. – Simon Righley Jan 29 '14 at 18:04
  • @BowlesCR it worked probably because your PS1 is not being set in any of the default rcfiles. In most cases, starting the new shell will overwrite the exported PS1 with whatever is in the default startup files. – terdon Jan 29 '14 at 18:05

For those, that cannot modify sshd config for various reasons and/or have +2000 servers (and no access to mass-configuration tools or can't/don't want to change settings for other users), here's a solution I came up with:

enter image description here

In PuTTY load the desired session, go to Connection > SSH. In the "Data to send to the server" section, in "Remote command" field use:

env [OPTION]... [-] [NAME=VALUE]... [COMMAND [ARG]...] bash


env -u PS1 PS1="[\u@\h]\\$ " bash

I unset the variable first, because it didn't work otherwise.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.