0

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

3
  • I’m sure there are reasons, but why not just use SSH forwarding over SSH? Commented Sep 9, 2022 at 20:26
  • I am not familiar what SSH forwarding is and how to implement that. Commented Sep 9, 2022 at 20:40
  • Meant to write X11 forwarding over SSH, sorry—Freudian slip! X11 forwarding is built into SSH, just check out the manual. Commented Sep 10, 2022 at 17:01

2 Answers 2

2

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.

2
  • Thanks! This worked and it answered my question. But as an addendum, as I was trying some things and I found out something else: Commented Sep 9, 2022 at 19:50
  • Thanks! This worked and it answered my question. But as an addendum, as I was trying some things and I found out something else: When I am trying the following: C:Windows\System32> ssh username@remote-ip firefox It tells me that Error: no display environment specified. However, if breakdown the the command into two steps, it works fine. C:Windows\System32> ssh username@remote-ip username@remote-ip:~ firefox Commented Sep 9, 2022 at 19:59
1

You'll want to add them to your startup scripts for your shell. Assuming your shell is bash, you'll add export DISPLAY=local-ip:10.0 to ~/.bashrc or ~/.bash_login. In this case, probably the latter.

However, you might try using the -X option to ssh if it accepts it. In some implementations it will set your display for you on the remote. This provides support for multiple users and multiple ssh sessions.

Demo:

$ ssh lima
$ echo $DISPLAY

$ exit
logout
Connection to lima closed.
$ ssh -X lima
$ echo $DISPLAY
localhost:10.0

And if I'm logged in from home session and someone else logs is...

$ ssh -X lima
$ echo $DISPLAY
localhost:11.0
6
  • Hey @brunson: Linux is my remote desktop. Should I make change over there? Commented Sep 9, 2022 at 19:06
  • Yes, modify the .bash_login on the remote machine. But try the -X and just echo your display to see if it gets set. See my edit in the answer Commented Sep 9, 2022 at 20:20
  • So, the suggestion from Kamil worked. However, as I was trying different methods following does not work: C:Windows\System32> ssh username@remote-ip firefox It gives me; Error: no display environment specified. Any suggestions? But it does work in two step process. C:Windows\System32> ssh username@remote-ip and then ~firefox Commented Sep 9, 2022 at 20:23
  • Also, using -X did not work. Commented Sep 9, 2022 at 20:24
  • What is your shell? Type echo $SHELL and also the output of cat ~/.bash_login But if the other solution worked, then that's good. Commented Sep 9, 2022 at 20:34

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.