Bosse_B
Posts: 794
Joined: Thu Jan 30, 2014 9:53 am

How to display the Pi desktop on PC

Sun Sep 27, 2015 12:25 pm

I would like to know how to proceed to display the Pi2 desktop on my Win7 PC.
I have full connection to the Pi running RaspBian via PuTTY and SSH, but that only gives me a command line interface.
Now I need to use Lazarus IDE for FreePascal development and I have no HDMI monitor to connect. But I have heard that it is possible to display the desktop on a PC instead using some networking functions like VNC or X.

Is there a complete tutorial for this somewhere?

I need to do this also over OpenVPN to a remote Pi where I currently only have command line access via PuTTY.
Bo Berglund
Sweden

User avatar
AndyD
Posts: 2331
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: How to display the Pi desktop on PC

Sun Sep 27, 2015 12:38 pm

There is a VNC tutorial on the Raspberry Pi Documentation.

Bosse_B
Posts: 794
Joined: Thu Jan 30, 2014 9:53 am

Re: How to display the Pi desktop on PC

Sun Sep 27, 2015 2:03 pm

Yeah, I fond that but it deals exclusively with command line interface except for VNC.
My past experiences with VNC have not been that great (on Windows) so I hoped there was something else available in the Linux world. Like X for example.
OTOH when we used X on Windows at work we had to cash up big dollars for the X server on Windows, not possible now that I am retired...
Bo Berglund
Sweden

User avatar
AndyD
Posts: 2331
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: How to display the Pi desktop on PC

Sun Sep 27, 2015 2:22 pm

OK, sorry I didn't read you original post in sufficient detail.

You can run an X server on your Windows machine using XMing. It is free.

klricks
Posts: 6587
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: How to display the Pi desktop on PC

Sun Sep 27, 2015 3:09 pm

RDP will give you the RPi desktop in Windows.
For Windows use Remote Desktop Connection which is already included in Windows.
For the RPi install:

Code: Select all

sudo apt-get update
sudo apt-get install xrdp
Note RDP will give you a new instance of the desktop independent of the main session at the RPi.
If you require control of the main session then you must install x11vnc instead.

If you need remote connection from external network then try Weaved for the RPi: https://www.weaved.com/#
(No port forwarding needed but you must sign up for the free service and install the client software).
Unless specified otherwise my response is based on the latest and fully updated Raspbian Buster w/ Desktop OS.

Bosse_B
Posts: 794
Joined: Thu Jan 30, 2014 9:53 am

Re: How to display the Pi desktop on PC

Sun Sep 27, 2015 7:12 pm

AndyD wrote: You can run an X server on your Windows machine using XMing. It is free.
OK,
I tried to get it but when I clicked on the link XMing-x64 it popped up a logon screen asking for username/password...
And there is a popup when you hover above it saying I need a donor password in order to download the "website release".
So it is not really free, right?
Or is there some other place it can be downloaded that is not a website???
Googling gave me Sourceforge Xming but it shows version 6.9.0.31 whereas the link you sent shows version 7.5.0.97.
I went ahead and got the SF one but after it is installed and I start it there is nothing displayed, just a system tray icon.
Is that normal?
How does one connect to the Pi?
I am probably missing something here, right?
Bo Berglund
Sweden

Bosse_B
Posts: 794
Joined: Thu Jan 30, 2014 9:53 am

Re: How to display the Pi desktop on PC

Sun Sep 27, 2015 8:53 pm

AndyD wrote:There is a VNC tutorial on the Raspberry Pi Documentation.
After trying to get going with various X11 servers and such I decided to skip that and go with VNC instead, as you suggested. I could not understand how X works so I could not create any desktop window at all. Uninstalled it all.
So I followed the VNC tutorial and got myself a desktop login to the Pi via TightVNC.

This is on a Pi1B+ at my daughter's place though, not the new Pi2B I will build when I get back home...
I hope it will work for Lazarus then I will be basically done.

One last question about disconnections:
How do I disconnect the Pi VNC connection? There seems not to be any such command...
And how do I shut down the VNC server on the Pi? It seemed to be started using a PuTTY command without using sudo so does it disappear if I close that PuTTY session?

Thanks for the pointers!
Bo Berglund
Sweden

User avatar
default_user8
Posts: 660
Joined: Mon Nov 18, 2013 3:11 am

Re: How to display the Pi desktop on PC

Sun Sep 27, 2015 9:00 pm

When you close the window that displays the vnc connection the session ends. As for stopping the vnc server there really isn't any need to, you should be using ssh to tunnel your vnc sessions since vnc is unencrypted. I do this on my pi and an old pc that I use as a dvr. I run ddwrt on my router that has its own ssh server, I just connect to my router and then I can log into my raspi and my pc, works like a cham from my android tablet and phone. A very handy setup.
Two heads are better than one, unless one's a goat head.

Bosse_B
Posts: 794
Joined: Thu Jan 30, 2014 9:53 am

Re: How to display the Pi desktop on PC

Sun Sep 27, 2015 10:13 pm

I used SSH via PuTTY in order to install and start tightvnc server on the Pi.
The start was done by a simple command (no sudo) on the command line in PuTTY.

But when I connected the TightVNC client from Windows on the internal network I did not see any mention of SSH there, so how does SSH come into play with TightVNC?

I also assumed I started a user level program running on the Pi, which would end when I closed PuTTY. But the VNC desktop remained... Strange.

Have I missed something?
(I follwed the tutorial about VNC up until but NOT including the section Automation and run at boot)
Bo Berglund
Sweden

User avatar
default_user8
Posts: 660
Joined: Mon Nov 18, 2013 3:11 am

Re: How to display the Pi desktop on PC

Sun Sep 27, 2015 10:28 pm

I mentioned vnc over ssh because you spoke of placing a pi at your daughter's house. I assume you would want to access that pi via internet with vnc. VNC being an unencrypted connection should be tunnelled via ssh to protect passwords etc.
When you started vncserver on your pi it runs in the background and serves up a display by display number that it number is displayed when you started the server(usually :1). To stop that server you could enter vncserver -kill :1, but there really isn't any need to stop it.
Two heads are better than one, unless one's a goat head.

Bosse_B
Posts: 794
Joined: Thu Jan 30, 2014 9:53 am

Re: How to display the Pi desktop on PC

Sun Sep 27, 2015 11:25 pm

Thanks,
then I understand.
In fact I have placed this Pi at her place in order to be able to access her network from where I live. It runs OpenVPN server so it also handles the encrypted connection.
I also have two Pi:s back home doing the same thing for my home network (two for redundancy since I was once locked out because the single OpenVPN server had locked up).
I would not publish the VNC port on the router....

Just came to think about this:
Now I could check out performance on my Rpi2 back home over VPN if I install TightVNC also on that while staying at my daughter's. After dinner....
Bo Berglund
Sweden

User avatar
default_user8
Posts: 660
Joined: Mon Nov 18, 2013 3:11 am

Re: How to display the Pi desktop on PC

Mon Sep 28, 2015 12:01 am

After going back and rereading your post I saw you run openvpn so yes you have your encrpyted connection covered. I don't have any experience with openvpn but I understand the basic concept. I run tightvnc server on my dvr computer so that I can set it to record shows when i'm away from home. It's quite handy.
Two heads are better than one, unless one's a goat head.

Bosse_B
Posts: 794
Joined: Thu Jan 30, 2014 9:53 am

Re: How to display the Pi desktop on PC

Sat Oct 03, 2015 9:46 pm

OK, so I have TightVNC installed on the Pi2B (server) and in Win7 (client).
The headless Pi2B displays a desktop via VNC on my Win7 monitor.

Is there any way to share the clipboard between the two systems such that I can copy a piece of text in Win7 and then paste it inside the Pi2 environment?
It would be a good way to transfer texts between code editors in the two systems.

I am now up and running with Lazarus/FreePascal on my Pi2B but all of my browsing for code snippets are done inside Win7 so it would help to be able to paste inside the Lazarus editor and vice versa.
Bo Berglund
Sweden

klricks
Posts: 6587
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: How to display the Pi desktop on PC

Sat Oct 03, 2015 10:23 pm

Bosse_B wrote:OK, so I have TightVNC installed on the Pi2B (server) and in Win7 (client).
The headless Pi2B displays a desktop via VNC on my Win7 monitor.

Is there any way to share the clipboard between the two systems such that I can copy a piece of text in Win7 and then paste it inside the Pi2 environment?
It would be a good way to transfer texts between code editors in the two systems.

I am now up and running with Lazarus/FreePascal on my Pi2B but all of my browsing for code snippets are done inside Win7 so it would help to be able to paste inside the Lazarus editor and vice versa.
I never could find a way to C&P using RDP either.
C&P does however work over SSH connection (Putty) in either direction.
Unless specified otherwise my response is based on the latest and fully updated Raspbian Buster w/ Desktop OS.

Bosse_B
Posts: 794
Joined: Thu Jan 30, 2014 9:53 am

Re: How to display the Pi desktop on PC

Sat Oct 03, 2015 10:49 pm

OK, I figured as much. :evil:

Another issue has popped up:
My VNC desktop is running as root on the Pi2B! This has non-wanted consequences for file access to the development files etc.

So my question now is if someone knows how to get the VNC window to run as user pi instead?
The instructions on the RPi VNC documentation page tells me to use this boot script:

Code: Select all

### BEGIN INIT INFO
# Provides: vncboot
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start VNC Server at boot time
# Description: Start VNC Server at boot time.
### END INIT INFO

#! /bin/sh
# /etc/init.d/vncboot

USER=pi
HOME=/home/pi

export USER HOME

case "$1" in
 start)
  echo "Starting VNC Server"
  #Insert your favoured settings for a VNC session
  su - pi -c "/usr/bin/vncserver :0 -geometry 1280x800 -depth 16 -pixelformat rgb565"
  ;;

 stop)
  echo "Stopping VNC Server"
  /usr/bin/vncserver -kill :0
  ;;

 *)
  echo "Usage: /etc/init.d/vncboot {start|stop}"
  exit 1
  ;;
esac

exit 0
As you can see it specifies user pi and home as /home/pi
But if I use this file I cannot start the server, there is an error message:

Code: Select all

[email protected]:/etc/init.d# /etc/init.d/vncboot start
Starting VNC Server
vncserver: Wrong type or access mode of /home/pi/.vnc.
If I take out the leading parameters of the start line so it reads like this then it works:

Code: Select all

/usr/bin/vncserver :0 -geometry 1280x800 -depth 16 -pixelformat rgb565
But then it runs as user root notwithstanding the export of pi and /home/pi a few lines earlier...

I don't understand this at all, I had not noticed the user thing until I went looking for the files Lazarus created when I tested some pascal code and found it in /root/tmp.

What can I do in order for the tightvnc window to be running as user pi?
Bo Berglund
Sweden

User avatar
AndyD
Posts: 2331
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: How to display the Pi desktop on PC

Sat Oct 03, 2015 11:12 pm

Bosse_B wrote:

Code: Select all

[email protected]:/etc/init.d# /etc/init.d/vncboot start
Starting VNC Server
vncserver: Wrong type or access mode of /home/pi/.vnc.
I think the answer to the question is in the error message. The VNC server creates a config file in the pi user's home directory. The complaint is that it is having trouble accessing the file. Can you run the following in a terminal on the Pi and post the results?

Code: Select all

ls -l ~/.vnc

Bosse_B
Posts: 794
Joined: Thu Jan 30, 2014 9:53 am

Re: How to display the Pi desktop on PC

Sat Oct 03, 2015 11:26 pm

Here you go, I listed the files in the pi directory too:

Code: Select all

[email protected] ~ $ ls -l -a
total 84
drwxr-xr-x 11 pi   pi    4096 Oct  3 23:19 .
drwxr-xr-x  3 root root  4096 May  6 22:20 ..
-rw-r--r--  1 root root    69 Oct  3 22:29 .asoundrc
-rw-------  1 pi   pi     339 Oct  3 22:30 .bash_history
-rw-r--r--  1 pi   pi     220 May  6 22:20 .bash_logout
-rw-r--r--  1 pi   pi    3243 May  6 22:20 .bashrc
drwxr-xr-x  4 root root  4096 Oct  3 22:29 .cache
drwxr-xr-x  8 root root  4096 Oct  3 22:30 .config
drwx------  3 root root  4096 Oct  3 22:29 .dbus
drwxr-xr-x  2 root root  4096 Oct  3 22:29 Desktop
drwxr-xr-x  2 root root  4096 Oct  3 22:29 .gstreamer-0.10
drwx------  2 root root  4096 Oct  3 22:29 .gvfs
drwx------  3 root root  4096 Oct  3 22:29 .local
-rw-r--r--  1 pi   pi     675 May  6 22:20 .profile
drwxr-xr-x  3 root root  4096 Oct  3 22:29 .themes
drwx------  2 pi   pi    4096 Oct  3 23:22 .vnc
-rwxr-xr-x  1 pi   pi      61 Oct  3 23:02 vnc.sh
-rw-------  1 root root   105 Oct  3 22:33 .Xauthority
-rw-------  2 pi   pi       0 Oct  3 23:19 .Xauthority-c
-rw-------  2 pi   pi       0 Oct  3 23:19 .Xauthority-l
-rw-------  1 root root 11356 Oct  3 23:01 .xsession-errors

[email protected] ~ $ ls -l ~/.vnc
total 12
-rw------- 1 pi pi    8 Oct  3 23:19 passwd
-rw-r--r-- 1 pi pi 1952 Oct  3 23:20 raspberrypi:0.log
-rwxr-xr-x 1 pi pi  225 Oct  3 23:19 xstartup
Bo Berglund
Sweden

Higgs
Posts: 43
Joined: Tue May 26, 2015 2:17 pm

Re: How to display the Pi desktop on PC

Sat Oct 03, 2015 11:31 pm

Don't know about your root/rights problem, but as for Cut-n-Paste between Windows and RPi, I installed autocutsel on Raspbian

http://www.nongnu.org/autocutsel/#download

I am using X11VNC server on the RPi though, not TightVNC, but I didn't see a distinction made on that website.

The only odd thing is that I have to start with a Cut from the server on RPi to Paste into Windows (I just type junk text in text apps). After that it works in both directions. Maybe there is some parameter that fixes that but I don't do c-n-p between them very often.

Bosse_B
Posts: 794
Joined: Thu Jan 30, 2014 9:53 am

Re: How to display the Pi desktop on PC

Sat Oct 03, 2015 11:44 pm

What exactly do the leading letters in the vncboot start command mean?

Code: Select all

 su - pi -c "/usr/bin/vncserver :0 -geometry 1280x900 -depth 16 -pixelformat rgb565" 
I suspect it has something to do with the uesr and permission settings since the behaviour changes if I insert or remove them. I have two tutorials and one uses them whereas the other does not....
Bo Berglund
Sweden

User avatar
AndyD
Posts: 2331
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: How to display the Pi desktop on PC

Sun Oct 04, 2015 12:09 am

Bosse_B wrote:Here you go, I listed the files in the pi directory too:

Code: Select all

[email protected] ~ $ ls -l -a
total 84
drwxr-xr-x 11 pi   pi    4096 Oct  3 23:19 .
drwxr-xr-x  3 root root  4096 May  6 22:20 ..
-rw-r--r--  1 root root    69 Oct  3 22:29 .asoundrc
-rw-------  1 pi   pi     339 Oct  3 22:30 .bash_history
-rw-r--r--  1 pi   pi     220 May  6 22:20 .bash_logout
-rw-r--r--  1 pi   pi    3243 May  6 22:20 .bashrc
drwxr-xr-x  4 root root  4096 Oct  3 22:29 .cache
drwxr-xr-x  8 root root  4096 Oct  3 22:30 .config
drwx------  3 root root  4096 Oct  3 22:29 .dbus
drwxr-xr-x  2 root root  4096 Oct  3 22:29 Desktop
drwxr-xr-x  2 root root  4096 Oct  3 22:29 .gstreamer-0.10
drwx------  2 root root  4096 Oct  3 22:29 .gvfs
drwx------  3 root root  4096 Oct  3 22:29 .local
-rw-r--r--  1 pi   pi     675 May  6 22:20 .profile
drwxr-xr-x  3 root root  4096 Oct  3 22:29 .themes
drwx------  2 pi   pi    4096 Oct  3 23:22 .vnc
-rwxr-xr-x  1 pi   pi      61 Oct  3 23:02 vnc.sh
-rw-------  1 root root   105 Oct  3 22:33 .Xauthority
-rw-------  2 pi   pi       0 Oct  3 23:19 .Xauthority-c
-rw-------  2 pi   pi       0 Oct  3 23:19 .Xauthority-l
-rw-------  1 root root 11356 Oct  3 23:01 .xsession-errors

[email protected] ~ $ ls -l ~/.vnc
total 12
-rw------- 1 pi pi    8 Oct  3 23:19 passwd
-rw-r--r-- 1 pi pi 1952 Oct  3 23:20 raspberrypi:0.log
-rwxr-xr-x 1 pi pi  225 Oct  3 23:19 xstartup
Hi, I had a go myself on Jessie. I am certainly having problems, but I am not getting the same issue as you.

The message above is complaining about the ~/.vnc directory. The listing you gave only shows the permissions of the directory. These permissions look correct. I would suggest that you try moving the ~/.vnc directory aside ("mv ~/.vnc ~/.vnc.old") and recreating it by running tightvncserver as the pi user.

User avatar
AndyD
Posts: 2331
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: How to display the Pi desktop on PC

Sun Oct 04, 2015 12:12 am

Bosse_B wrote:What exactly do the leading letters in the vncboot start command mean?

Code: Select all

 su - pi -c "/usr/bin/vncserver :0 -geometry 1280x900 -depth 16 -pixelformat rgb565" 
I suspect it has something to do with the uesr and permission settings since the behaviour changes if I insert or remove them. I have two tutorials and one uses them whereas the other does not....
The su command is used to become another user, in this case the pi user.

Bosse_B
Posts: 794
Joined: Thu Jan 30, 2014 9:53 am

Re: How to display the Pi desktop on PC

Sun Oct 04, 2015 6:41 am

I think I understand it now....
Here is a summary of what I figured out.
1) the command: su - pi -c "something"
It sets the user for the created command shell as pi and invokes the command something using pi:s logon data. I checked with man su:

Code: Select all

NAME
       su - change user ID or become superuser

SYNOPSIS
       su [options] [username]

DESCRIPTION
       The su command is used to become another user during a login session. Invoked
       without a username, su defaults to becoming the superuser. The optional argument -
       may be used to provide an environment similar to what the user would expect had the
       user logged in directly.

       Additional arguments may be provided after the username, in which case they are
       supplied to the user's login shell. In particular, an argument of -c will cause the
       next argument to be treated as a command by most command interpreters. The command
       will be executed by the shell specified in /etc/passwd for the target user.
2) Why did it not work?
It seems like one has to manually once run the command from the pi user home directory:

Code: Select all

/usr/bin/vncserver :0 -geometry 1280x900 -depth 16 -pixelformat rgb565
At this time the home directory must be empty of the .vnc dir and also of the .Xauthority file, which seems to be a lock file of some kind. If .Xauthority exists it will delay the execution of the manual command for a while but there seems to be a timeout.
So the correct sequence of installing tightvnc server is:

Code: Select all

sudo apt-get install tightvncserver
tightvncserver (here the server's logon password will be entered)
vncserver :0 -geometry 1280x800 -depth 16 -pixelformat rgb565 (this creates the .vnc dir and lock files)
Following this the vncboot script is created and activated with the proper USER and HOME settings and the full start command as described above.
Now the VNC shell will be executed as the pi user.
Bo Berglund
Sweden

Return to “General discussion”