DEV Community

Discussion on: Customizing Your Shell Prompt for Productivity

Collapse
ikirker profile image
Ian Kirker

Fun-but-slightly-fragile fact: if you are SSH-ing to servers that don't reset the prompt, you can send your own by setting up ssh to send over your PS1 variable (the variable that contains the prompt specification for bash), and setting up the sshd to accept it.

In your /etc/ssh/sshd_config:

AcceptEnv PS1

And then:

ssh -o SendEnv=PS1 myserver.example.com

Or add it to your ~/.ssh/config file:

SendEnv PS1

(If you customise the other types of prompt as well, those are PS2, 3, and 4, and you can send those as well: just separate with whitespace. And check man ssh_config for more info.)

Collapse
nikoheikkila profile image
Niko Heikkilä Author

I was not aware of this feature. Quite cool, although it smells of remote code execution and therefore maybe not many SSH targets have this enabled by default?

Collapse
ikirker profile image
Ian Kirker

Well, at that point you're already doing remote code execution manually by logging in. But, yes, the default is to not accept any environment variables, so it would only work if you already have the ability to alter the SSH daemon configuration. If you have that, you already have sufficient permissions to do almost anything to the machine anyway.

I guess a use case would be if you were deploying an OS image and didn't want to bake your prompt into it, but still wanted it available.