Pushing my PS1 prompt over ssh
Solution 1:
Upload a file on each remote machine, say ~/.my_custom_bashrc
, with your custom bash
configuration, (in this case PS1=...
) then launch ssh
with:
ssh user@host -t "bash --rcfile ~/.my_custom_bashrc -i"
You can easily use a bash
function as wrapper for readability.
Solution 2:
If you just want to send the PS1
variable, and it doesn't contain a '
(single quote), try:
ssh targethost -t "PS1='$PS1'; exec bash"
The local .bashrc
may well overwrite PS1
though (thanks to Dennis Williamson for pointing this out).
There are ways to transmit environment variables over ssh, but they're typically disabled in the server configuration. If the PermitUserEnvironment
directive is enabled in the server configuration and each user has their own key pair (yeah, you might not be so lucky), you can add environment="PS1=…"
to the line in ~/.ssh/authorized_keys
corresponding to your key.
If you'd like to keep your own configuration on a shared user account, you can create your own configuration file directory and set the HOME
environment variable to point to that directory.
ssh targethost mkdir mrstatic.home
scp .bashrc targethost:mrstatic.home/
Create symbolic links in the mrstatic.home
directory pointing back to the corresponding entry in the parent directory when you want to share a file with the other users.
Then, log in with
ssh targethost -t 'HOME=~/mrstatic.home; exec bash'`
If you're willing to modify the remote .profile
(or other initialisation file), you can probably automate your settings. Many sites allow LC_*
environment variables through (normally they are used for locale settings). If both these conditions are met, you can set a variable that isn't actually used for locales, say LC_USER
, on the client side, and test it in the server .profile
.
(Of course shared accounts are a bad idea, but I realize you may not be in a position to change that situation.)