bratkartoffel
Posts: 1
Joined: Fri Jun 15, 2012 9:15 am
Location: Germany

[Howto] Redirect X over SSH to other PC

Fri Jun 15, 2012 9:23 am

Hi folks,

been playing around with my pi without any hdmi-capeable monitor. So i just plugged it in and tried to start the graphical environment over ssh.

The aim of this short Howto is to redirect the graphical environment to your laptop or pc over network.

1. Plug in your raspberry pi
2. Start a second X-Server on your pc:
2.1 As normal user: sudo xinit -- :1 &
2.2. Switch back to your primary desktop with "Ctrl + Alt + F7"
3.3. Leave this console window open!
3. Start LXDE-Session over network and redirect X
3.1 As normal User: DISPLAY=:1 ssh -X [email protected]<ip of your pi> lxsession
3.2 Enter your password and leave this console window open!

Now you can switch between your local und the remote Desktop simply with the keystrokes "Ctrl + Alt + F7 or F8.

- Do not close the Console window responsible for the X-Connection.
- Bug? When logging out from or shutting down the pi my laptop "crashes". Display turns off and won't turn on again. Have to restart my laptop.

Regards,
Simon

shawnanastasio
Posts: 19
Joined: Mon May 28, 2012 7:44 pm

Re: [Howto] Redirect X over SSH to other PC

Thu Jun 21, 2012 4:23 pm

Couldn't you just start a new X Session, login to the pi with "ssh -Y [email protected]", and type "lxsession"?

User avatar
jojopi
Posts: 3069
Joined: Tue Oct 11, 2011 8:38 pm

Re: [Howto] Redirect X over SSH to other PC

Thu Jun 21, 2012 5:12 pm

Which simplifies to:

Code: Select all

xinit /usr/bin/ssh -Y [email protected] lxsession -- :1
(Provided that ssh is configured correctly. You either need the openssh-askpass package installed, so that passwords can be read with no terminal; or a key and agent configured, so that no password is needed.)

User avatar
psergiu
Posts: 223
Joined: Mon Nov 07, 2011 8:36 am
Location: TX, U.S.A. (was: RO, E.U.)
Contact: Website

Re: [Howto] Redirect X over SSH to other PC

Thu Jun 21, 2012 6:40 pm

One more way (for Debian):

Following steps need to be done only once:
1) login on the RPi as root
2) edit /etc/gdm/gdm.conf
3) in the [xdmcp] section add: Enable=1
4) if you want to disable the startup of X on the Pi, edit /usr/share/gdm/defaults.con and put a # in front of the line "0=Standard device=/dev/console" (around row 604)
5) service gdm start
6) insserv gdm

Now, each time you want to connect, from the other Linux/Unix/OSX/Windows_with_cygwin box run from under X11:

Xnest -query address.of.your.pi

Or, from a linux box in Text mode

X :1 -query address.of.your.pi

(might have to edit /etc/X11/xinit/xserverrc and remove "-nolisten TCP" for this.

Login to the RPi and enjoy X Windows as it was intended - with X-Terminals connecting to a single machine.
Now, you can open as many sessions to your RPi as you want (until you fill up the RAM)
If you find an old "X Terminal" box in a second-hand computer store you can use-it this way as a remote display for your Pi.

Chuckaluphagus
Posts: 23
Joined: Sat Jun 30, 2012 9:05 pm

Re: [Howto] Redirect X over SSH to other PC

Sat Jun 30, 2012 9:13 pm

Bratkartoffel and others, thank you very much for posting this set of instructions. I would like to make a minor addendum: this didn't work off the bat for me, when I was attempting to forward the LXDE desktop to my laptop computer as a second session on tty1. I'd never get anything other than a blank screen on tty1.

I'm running Ubuntu 12.04 64-bit, and in order to get these instructions to function, I first needed to stop gdm by running "sudo gdm stop" at the command line. After that, bratkartoffel's instructions worked perfectly.

I'm not familiar enough with Linux or desktop environments to know why stopping gdm was necessary, but it doesn't interfere with my regular Unity desktop on tty0. Thought I'd post here just in case someone else is finding the same problem I was.

User avatar
jojopi
Posts: 3069
Joined: Tue Oct 11, 2011 8:38 pm

Re: [Howto] Redirect X over SSH to other PC

Sun Jul 01, 2012 1:43 am

Chuckaluphagus wrote:I'm not familiar enough with Linux or desktop environments to know why stopping gdm was necessary, but it doesn't interfere with my regular Unity desktop on tty0.
You may be confusing virtual console numbers, ttyN, with X display numbers, :N.

ttyN, where N is typically 1..12, is the console that you see after you press Ctrl+Alt+FN, and tty0 is a special device referring to the current console.

:N, where N is typically 0..9, refers to the Nth different X server on the host, usually counting from zero.

Many X servers allocate a virtual console, though some such as Xvnc and Xnest do not. When a console is allocated, it is usually either the one X was started from or the first one that is free. The console number almost never corresponds to the display number.

It should not be necessary to stop gdm before starting another X server with an ssh-tunnelled session. But if you have more than one X server already running, or if the first is already numbered :1, then you will need to change the references to :1 in the commands to some higher number. In any case, you may need to experiment to find which console each server has loaded on.

Chuckaluphagus
Posts: 23
Joined: Sat Jun 30, 2012 9:05 pm

Re: [Howto] Redirect X over SSH to other PC

Sun Jul 01, 2012 4:50 pm

jojopi wrote:You may be confusing virtual console numbers, ttyN, with X display numbers, :N.
My apologies for any confusion, I'm just learning this stuff.
It should not be necessary to stop gdm before starting another X server with an ssh-tunnelled session. But if you have more than one X server already running, or if the first is already numbered :1, then you will need to change the references to :1 in the commands to some higher number. In any case, you may need to experiment to find which console each server has loaded on.
I've now tried this, and it doesn't appear to make any difference. Unless I've stopped gdm first,

Code: Select all

sudo xinit -- :<number>
(where <number> is any number between 1 and 6) in a terminal returns an output like this

Code: Select all

[1] 2481
but does not create another X session that I can then use for forwarding from the Raspberry Pi. But, if I do stop gdm first, then it works perfectly.

rasbeer
Posts: 242
Joined: Wed Mar 07, 2012 8:35 am

Re: [Howto] Redirect X over SSH to other PC

Sun Jul 01, 2012 8:12 pm

bratkartoffel wrote: 1. Plug in your raspberry pi
2. Start a second X-Server on your pc:
2.1 As normal user: sudo xinit -- :1 &
2.2. Switch back to your primary desktop with "Ctrl + Alt + F7"
3.3. Leave this console window open!
...
Now you can switch between your local und the remote Desktop simply with the keystrokes "Ctrl + Alt + F7 or F8.
I just tried sudo xinit -- :1 & in a terminal emulator window and a virtual terminal, and "Ctrl + Alt + F8" just gives a black screen with a blinking cursor. (This is on Ubuntu 11.10.)

I haven't got a Pi to plug in, but presumably that's not a requirement for starting a second X server...

User avatar
bob_binz
Posts: 441
Joined: Thu Feb 02, 2012 7:58 pm
Location: Stockport, UK

Re: [Howto] Redirect X over SSH to other PC

Sun Jul 01, 2012 8:48 pm

Having used a command such as

Code: Select all

sudo xinit -- :1
how does one go about killing the newly spawned x session, :1 without killing :0 ??

rasbeer
Posts: 242
Joined: Wed Mar 07, 2012 8:35 am

Re: [Howto] Redirect X over SSH to other PC

Mon Jul 02, 2012 6:17 am

rasbeer wrote:I just tried sudo xinit -- :1 & in a terminal emulator window and a virtual terminal, and "Ctrl + Alt + F8" just gives a black screen with a blinking cursor. (This is on Ubuntu 11.10.)
OK - I see from Bob's post that it's sudo xinit -- :1 & (ie sudo xinit --[space]:1 &.

Once again I tried it in both the terminal emulator window and a virtual terminal, but still, nothing happens :?

Chuckaluphagus
Posts: 23
Joined: Sat Jun 30, 2012 9:05 pm

Re: [Howto] Redirect X over SSH to other PC

Mon Jul 02, 2012 2:39 pm

rasbeer wrote:I just tried sudo xinit -- :1 & in a terminal emulator window and a virtual terminal, and "Ctrl + Alt + F8" just gives a black screen with a blinking cursor. (This is on Ubuntu 11.10.)

I haven't got a Pi to plug in, but presumably that's not a requirement for starting a second X server...
On Ubuntu 12.04, I needed to stop gdm first (see my post above) before running xinit to create the second session. Otherwise I have the exact same result as you, just a black screen with a blinking cursor. I don't know why it's necessary to do so, but for me it doesn't work otherwise.

rasbeer
Posts: 242
Joined: Wed Mar 07, 2012 8:35 am

Re: [Howto] Redirect X over SSH to other PC

Mon Jul 02, 2012 3:07 pm

Hmm - I tried sudo gdm stop, but it appears gdm wasn't running. I'm running Xubuntu 11.10, and it seems this uses LightDm instead of GDM.

But:

Code: Select all

$sudo lightdm stop
Failed to use bus name org.freedesktop.DisplayManager, do you have appropriate permissions?
:?

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: [Howto] Redirect X over SSH to other PC

Mon Jul 02, 2012 3:50 pm

Incidentally, the use of "sudo" should not be necessary in any of the command lines on this thread. In fact, AIUI, the whole general point of "sudo" - the general justification for it - is to *prevent* you from running X as root. By doing things like "sudo xinit" and/or "sudo startx", you are explicitly defeating this intended purpose.

In fact, this seems to be the proof positive of what I've been saying all along - that "sudo" is just what you do when you get an error message - try it again with "sudo".

And of course, this rant wouldn't be complete without posting this:

$ rm -rf /
(error messages)
$ sudo rm -rf /
$

And on to the next task...

sudo is soooooo stooooopid!
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

rasbeer
Posts: 242
Joined: Wed Mar 07, 2012 8:35 am

Re: [Howto] Redirect X over SSH to other PC

Mon Jul 02, 2012 4:07 pm

Joe Schmoe wrote: And of course, this rant wouldn't be complete without posting this:

$ rm -rf /
(error messages)
$ sudo rm -rf /
$
Just reading this makes me nervous!

User avatar
psergiu
Posts: 223
Joined: Mon Nov 07, 2011 8:36 am
Location: TX, U.S.A. (was: RO, E.U.)
Contact: Website

Re: [Howto] Redirect X over SSH to other PC

Mon Jul 09, 2012 1:04 pm

If you want to start another X server on linux, you can also specify the tty:

xinit -- vt8 :1

starts XServer :1 on tty8 (Ctrl-alt-F8)

just make sure beforehand that tty is "empty" i.e. there's no getty asking for a login prompt or syslog dumping messages there.

PS: has anyone tried my method ?

Chuckaluphagus
Posts: 23
Joined: Sat Jun 30, 2012 9:05 pm

Re: [Howto] Redirect X over SSH to other PC

Mon Jul 09, 2012 7:17 pm

psergiu wrote:If you want to start another X server on linux, you can also specify the tty:

xinit -- vt8 :1

starts XServer :1 on tty8 (Ctrl-alt-F8)

just make sure beforehand that tty is "empty" i.e. there's no getty asking for a login prompt or syslog dumping messages there.

PS: has anyone tried my method ?
I just tried it now. Unfortunately, it doesn't work for me - the screen blanks, and if I then hit Ctrl-Alt-F7 to get back to my original X session, I have an XTerm window open as root (I have to preface the "xinit -- vt8 :1" command with sudo; my regular user account doesn't have permission).

I did check beforehand as you suggest, tty8 (or 9, or 10 etc.) doesn't show me anything other than a black screen with a blinking cursor.

perpe
Posts: 30
Joined: Fri May 25, 2012 6:44 pm

Re: [Howto] Redirect X over SSH to other PC

Wed Jul 11, 2012 10:26 am

With Ubuntu 12.04 on my laptop it works for my with this steps:

On Pi: open the file /etc/ssh/sshd_config and make sure that "X11Forwarding yes" is activated (remove the # in front of the line or if there is a "X11Forwarding no" change it to yes. Restart ssh server with

Code: Select all

sudo /etc/init.d/ssh restart
or reboot

On your Ubuntu machine run

Code: Select all

sudo dpkg-reconfigure x11-common
Select "Anybody" in the next options to allow starting x from pi(attention: Security risk, change back if you don't need it) You may need to restart x.
Now, you can connect to your pi with

Code: Select all

xinit -e ssh -XY [email protected]<your_ip> lxsession -- :1
Don't close the terminal window. You can switch between your machines desktop and Pi desktop with ctrl+Alt+F7 and ctrl+Alt+F8.

If you don't need to access the whole pi desktop and want only one pi application shown on your maschine's desktop you can login with

Code: Select all

ssh -X [email protected]<your_ip> <application_name>
replace <application_name> with the application name you want to start, for example leafpad. For this you don't need to run the dpkg-reconfigure command.

cwd
Posts: 1
Joined: Wed Jul 18, 2012 3:39 pm

Re: [Howto] Redirect X over SSH to other PC

Wed Jul 18, 2012 7:05 pm

Maybe there is something wrong with doing it this way but I can SSH to my raspberry pi using an identity key and X forwarding

Code: Select all

ssh -i /path/to/key.pem [email protected] -X 
and then just run

Code: Select all

lxsession
to start the lde:


Image

UncleVan
Posts: 16
Joined: Fri Dec 28, 2012 7:43 pm

Re: [Howto] Redirect X over SSH to other PC

Wed Jan 30, 2013 5:26 am

In my case xinit didnt work either , so I did it my way:

Code: Select all

X :1 vt8 &
and then

Code: Select all

DISPLAY=:1 ssh -p 2222 -Y [email protected] lxsession
(port 2222 and localhost because Im running qemu-system-arm).
Anyway, I find this great:
jojopi wrote:Which simplifies to:

Code: Select all

xinit /usr/bin/ssh -Y [email protected] lxsession -- :1
(Provided that ssh is configured correctly. You either need the openssh-askpass package installed, so that passwords can be read with no terminal; or a key and agent configured, so that no password is needed.)
But can somebody please explain how exactly is this supposed to work with openssh-askpass ? - Because there is no way to tipp the password else - Thanks in advance !

pixming
Posts: 1
Joined: Sat May 07, 2016 3:09 am

Re: [Howto] Redirect X over SSH to other PC

Sat May 07, 2016 3:34 am

I used information from this forum and created two convenient commands on my Ubuntu 14.04 box:

rpi, to start Xorg connected to the Raspberry Pi:

Code: Select all

#!/bin/bash
sudo su -c "X :1 -query 192.168.199.8 &"
and, obviously, rpi_kill, to get rid of the instance of Xorg when I am done with it:

Code: Select all

#!/bin/bash
if [ -z $(pgrep -f -n "X :1") ]; then
  echo "only one Xorg running, aborted"
  exit
fi
echo "killing last started Xorg"
sudo kill $(pgrep -f -n "X :1")
I have the two commands in my ~/bin directory, both made executable with chmod +x ~/bin/rpi and chmd +x ~/bin/rpi_kill
They can be improved to use other instances of X (:1 in my case) and even multiple instances with coordination between rpi and rpi_kill to terminate the desired instance only. The important fact is that the rpi_kill script preserves other instances of Xorg and cleanly closes the target one.

Return to “Advanced users”