How can I set persistent display settings for SSH?

Dwight Schrute

I am remoting into Linux machine from my Windows PC using SSH. I am right now following steps:

  1. C:Windows\system32> ssh username@remote-ip

    (Since I have key type authentication set up, I do not need passwords.)

  2. username@remote-ip:~ export DISPLAY=local-ip:10.0

  3. 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)?

Kamil Maciorowski

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.

edited at
0

Comments

0 comments
Login to comment

Related

How can I make ACL settings on /run/media/* persistent?

How can I modify client SSH settings?

TortoiseGit: Settings "remote" missing. How can I set SSH key without having a cloned repository?

How can I set default settings for htop?

How can I set proxysettings for SSH in eclipse?

How can I reference my UserControls to display them on the Settings pane?

How can I restore my display settings in windows 10?

How can I preserve the brightness settings of my laptop display on standby?

How can I reset my display settings through terminal?

How can I set the display range of a QGraphicItemGroup?

How can I make Windows 10's ssh-add non-persistent?

How can I set Firefox settings with a bash scipt?

How can I run a program remotely via SSH but display locally

How can I find the mapping on `$DISPLAY` after `ssh -X`?

On a Mac Sierra, how can I give an ssh session access to the display?

How can I display xeyes on a remote host without using SSH?

How do I make xinput mouse settings persistent for a USB mouse?

When start strict mode and set `android:persistent` to `true` will has error. How can I fix this error?

How can I set persistent data in docker-compose.yml file

How can I make this modal persistent?

How can I set my computer up for remote SSH access?

How can I set up password-less SSH login?

How can I set up smart card SSH authentication?

How i can save settings to the application Settings?

How can I have my display settings automatically restored after I play a full-screen game?

Fix broken display settings - persistent LiveUSB

Can I set SMTP settings in the Azure Portal?

How to display persistent dialogue

How can I save SSH tunnel settings with multi-factor authentication in PuTTY or mRemoteNG?