I hope i have a rather easy to answer question even tho i did not found any solution while googeling. Only things i found is guides how to change the profile. This i know.
So i basically want a different profile if im using ssh. Basically i have at least a ssh connection open and my local terminal (both with byobu running, so combining both into one byobu would be a bit confusing to navigate).
why/motivation: So as i confuse them form time to time which is super annoying because some commands i can only run successfully on the cluster im login into but due the 3rd party tool (dvc) it taskes sometimes quite i while to run the command and then just to fail because i run it on the wrong machine.
Thats why i just want a different profile/background color for my terminal if used ssh.
Is this possible? Or any other idea to archive some similar behavior? Basically im happy if i got a different background color in my terminal as soon as i connected via ssh.
Enable the ssh manager plugin in konsole and specify the profile you want to use for the ssh sessions you define.
You’d need to start the ssh session using the ssh manager, but it’d do what you want.
IS there another option where i dont have to use the ssh-manager? I want to set it up one time and then every time i e.g run ssh someserver for somesserver what ever profile is used.
It’ll be a bit hacky but you could use the concepts of this link to do what you want:
Then create an alias that uses those concepts to change the colors when you type the ssh command.
For the case of the target machine where the SSH Daemon has accepted your SSH Client session – “man 8 sshd” –
When a user successfully logs in, sshd does the following:
1. If the login is on a tty, and no command has been specified, prints last login time and /etc/motd
(unless prevented in the configuration file or by ~/.hushlogin; see the FILES section).
2. If the login is on a tty, records login time.
3. Checks /etc/nologin; if it exists, prints contents and quits (unless root).
4. Changes to run with normal user privileges.
5. Sets up basic environment.
6. Reads the file ~/.ssh/environment, if it exists, and users are allowed to change their environment.
See the PermitUserEnvironment option in sshd_config(5).
7. Changes to user's home directory.
8. If ~/.ssh/rc exists and the sshd_config(5) PermitUserRC option is set, runs it; else if
/etc/ssh/sshrc exists, runs it; otherwise runs xauth. The “rc” files are given the X11 authentica-
tion protocol and cookie in standard input. See SSHRC, below.
9. Runs user's shell or command. All commands are run under the user's login shell as specified in the
system password database.
Then, on the target machine, the following Environment variables are created and set:
And, the parent process of the remote session is “sshd”.
Answer here on serverfault: <https://serverfault.com/questions/187712/how-to-determine-if-im-logged-in-via-ssh>
And, StackExchange: <https://unix.stackexchange.com/questions/9605/how-can-i-detect-if-the-shell-is-controlled-from-ssh/>
I’ve absolutely no idea if, based on the answer of “throttlemeister”, it’s possible to change the Konsole colour scheme by means of actions at the other end of an SSH session – I suspect not.
- On the other hand, as “throttlemeister” suggests, you could redefine, for your user sessions, the behaviour of the “ssh” command …
So i solved it a bit differently as you suggested and it for sure not a very clean solution as it requires that i ajust my dotfiles a bit more.
But i added the following into my zshrc
alias ssh="konsoleprofile "colors=myssh" && ssh "
Which the drawback i need to:
- ajust my dotfiles
- have a colorscheme fitting the name in the alias
- overwrite ssh with an dirty alias, which i dont prefer but i dont find a working solution for myself
I tried to ajust the profiles like @throttlemeister suggested but i didnt get it to work. And @Franken14679 i did not really understood how to set up yours.
Assuming that, I had a need to do something like this, I would adopt the method for the Bash Profile mentioned in StackExchange (SSH_CLIENT / SSH_TTY / sshd) to limit what the SSH session can by means of the Bash shell.
I setup the Konsole tabs such that each session has a mostly unique background colour plus, any Tabs which are running remote (including SSH) sessions are setup with the following text:
(Remote user plus, remote Hostname)