I am remoting into Linux machine from my Windows PC using SSH. I am right now following steps:
C:Windows\system32> ssh username@remote-ip
(Since I have key type authentication set up, I do not need passwords.)
username@remote-ip:~ export DISPLAY=local-ip:10.0
username@remote-ip:~ firefox
#example
This runs fine.
However each time I SSH, I have to execute step 2.
Can I add that parameter to some config file (sshd config file or SSH config file or ssh argument so that I do not have to type that all the time?
Where should I make the change: On the remote PC (Linux) or local PC (Windows)?
A possible solution is to do this via a startup script of your shell on the server side.
Depending on the shell, it may or may not source some script(s) when started as an interactive shell by an SSH server. In case of Bash the script is ~/.bashrc
.
I assume your shell on the server side does source some script. If I were you, I would define the variable there. First I would check if SSH is involved, next if $DISPLAY
expands to an empty string (in case it's already set because of ssh -X
), then I would set it. The code may be:
[ -n "$SSH_CONNECTION" ] && [ -z "$DISPLAY" ] && export DISPLAY=local-ip:10.0
$SSH_CONNECTION
is explained and used less trivially in this another answer.
Note in some circumstances the startup script may return early. E.g. in this answer, twist number 3. Note the linked answer is about non-interactive shells and your ssh username@remote-ip
gives you an interactive shell; still in general the startup script may contain some logic that allows it to return early for some reason. It may also already contain DISPLAY=…
. Inserting the above code at the end may be wrong if there's return
. Inserting the above code at the beginning may be wrong if there's DISPLAY=…
. In general you need to understand the logic of the startup script and insert the above code in the right place. When in doubt, insert at the beginning and see if it works.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments