0

I just got a new server and as I wanted to transition from Ubuntu to Debian, installed Debian 10 on there. Im Using OpenSSH provided by Windows to login (OpenSSH_for_Windows_7.7p1, LibreSSL 2.6.5) I now have the problem that when I have both servers open, one does have the current user and the hostname of my machine, as well as the current director I'm in, "OpenSSH SSH Client" and I would like to change that.

I so far figured out that I can change my window title to something with this command:

echo -ne "\033]0;Test\007"

in this case to Test.

Now my question, how do I change that on a sucessfull connection and depending on the user and hostname (which in this case is static, but I would like to know that for the future)?

Since I'm new And Can't embed Pictures, here's the Direct Link: https://i.stack.imgur.com/BUKjt.png

2
  • 1
    What shell are you using on the remote server? – bk2204 Oct 8 '20 at 21:11
  • bin/bash, if that's what you mean – ScarVite Oct 9 '20 at 5:38
0

In your ~/.bashrc on the remote server, you can add a line like this:

if [ -n "$PS1" ]
then
    printf '\033]0;%s@%s\007' "$(id -un)" "$(hostname)"
fi

That will keep the operation from running when you run a script or command non-interactively over SSH.

Note that many people prefer to keep their dotfiles in a Git repository and deploy them on every system they work with. If that's the case for you, you may decide you only want this behavior when logging in over SSH. If so, you can do this:

if [ -n "$SSH_TTY" -a -n "$PS1" ]
then
    printf '\033]0;%s@%s\007' "$(id -un)" "$(hostname)"
fi

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.