-
- Posts: 1
- Joined: Fri Jun 15, 2012 9:15 am
- Location: Germany
[Howto] Redirect X over SSH to other PC
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 pi@<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
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 pi@<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
-
- Posts: 19
- Joined: Mon May 28, 2012 7:44 pm
Re: [Howto] Redirect X over SSH to other PC
Couldn't you just start a new X Session, login to the pi with "ssh -Y pi@myipaddress", and type "lxsession"?
Re: [Howto] Redirect X over SSH to other PC
Which simplifies to:
(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.)
Code: Select all
xinit /usr/bin/ssh -Y pi@pi lxsession -- :1
- psergiu
- Posts: 224
- 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
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.
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.
-
- Posts: 23
- Joined: Sat Jun 30, 2012 9:05 pm
Re: [Howto] Redirect X over SSH to other PC
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.
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.
Re: [Howto] Redirect X over SSH to other PC
You may be confusing virtual console numbers, ttyN, with X display numbers, :N.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.
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.
-
- Posts: 23
- Joined: Sat Jun 30, 2012 9:05 pm
Re: [Howto] Redirect X over SSH to other PC
My apologies for any confusion, I'm just learning this stuff.jojopi wrote:You may be confusing virtual console numbers, ttyN, with X display numbers, :N.
I've now tried this, and it doesn't appear to make any difference. Unless I've stopped gdm first,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.
Code: Select all
sudo xinit -- :<number>
Code: Select all
[1] 2481
Re: [Howto] Redirect X over SSH to other PC
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.)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 haven't got a Pi to plug in, but presumably that's not a requirement for starting a second X server...
Re: [Howto] Redirect X over SSH to other PC
Having used a command such as
how does one go about killing the newly spawned x session, :1 without killing :0 ??
Code: Select all
sudo xinit -- :1
Re: [Howto] Redirect X over SSH to other PC
OK - I see from Bob's post that it's sudo xinit -- :1 & (ie sudo xinit --[space]:1 &.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.)
Once again I tried it in both the terminal emulator window and a virtual terminal, but still, nothing happens

-
- Posts: 23
- Joined: Sat Jun 30, 2012 9:05 pm
Re: [Howto] Redirect X over SSH to other PC
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 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...
Re: [Howto] Redirect X over SSH to other PC
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:

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

-
- Posts: 4277
- Joined: Sun Jan 15, 2012 1:11 pm
Re: [Howto] Redirect X over SSH to other PC
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!
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)
(One of the best lines I've seen on this board lately)
Re: [Howto] Redirect X over SSH to other PC
Just reading this makes me nervous!Joe Schmoe wrote: And of course, this rant wouldn't be complete without posting this:
$ rm -rf /
(error messages)
$ sudo rm -rf /
$
- psergiu
- Posts: 224
- 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
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 ?
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 ?
-
- Posts: 23
- Joined: Sat Jun 30, 2012 9:05 pm
Re: [Howto] Redirect X over SSH to other PC
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).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 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.
Re: [Howto] Redirect X over SSH to other PC
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 or reboot
On your Ubuntu machine run
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
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
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.
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
On your Ubuntu machine run
Code: Select all
sudo dpkg-reconfigure x11-common
Now, you can connect to your pi with
Code: Select all
xinit -e ssh -XY pi@<your_ip> lxsession -- :1
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 pi@<your_ip> <application_name>
Re: [Howto] Redirect X over SSH to other PC
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 and then just run to start the lde:

Code: Select all
ssh -i /path/to/key.pem pi@123.456.789.012 -X
Code: Select all
lxsession

Re: [Howto] Redirect X over SSH to other PC
In my case xinit didnt work either , so I did it my way:
and then(port 2222 and localhost because Im running qemu-system-arm).
Anyway, I find this great:
Code: Select all
X :1 vt8 &
Code: Select all
DISPLAY=:1 ssh -p 2222 -Y root@localhost lxsession
Anyway, I find this great:
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 !jojopi wrote:Which simplifies to:(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.)Code: Select all
xinit /usr/bin/ssh -Y pi@pi lxsession -- :1
Re: [Howto] Redirect X over SSH to other PC
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:
and, obviously, rpi_kill, to get rid of the instance of Xorg when I am done with it:
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.
rpi, to start Xorg connected to the Raspberry Pi:
Code: Select all
#!/bin/bash
sudo su -c "X :1 -query 192.168.199.8 &"
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")
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.