Start VNC server at boot or restart

Post Reply
dstair
Posts: 41
Joined: Sun Oct 22, 2017 1:21 am
languages_spoken: english
ODROIDs: XU4, HC1, HC2, MC1
Location: United States, Indiana
Contact:

Start VNC server at boot or restart

Unread post by dstair » Wed Nov 21, 2018 1:50 pm

I have successfully been able to log into and set up my machine using real vnc. I have recently created a systemd startup service to start my VNC server on boot or reboot. The service file is as follows
[Unit]
Description=Systemd VNC server startup script for HC2 running Ubuntu 18.04 LTS
Requires=multi-user.target
Wants=display-manager.service
Conflicts=rescue.service rescue.target
After=multi-user.target rescue.service rescue.target display-manager.service syslog.target network.target
AllowIsolate=yes

[Service]
Type=forking
User=myusername
Group=myusernamegroup
WorkingDirectory=/home/myusername

PIDFile=/home/dstair/.vnc/%H:%i.pid
ExecStartPre=-/usr/bin/vncserver -kill :%i > /dev/null 2>&1
ExecStart=/usr/bin/vncserver -depth 24 -geometry 1920x1080 :%i
ExecStop=/usr/bin/vncserver -kill :%i

[Install]
WantedBy=multi-user.target

I can access the server but I have admin issues where I cannot open files or things just do not work. If I log out of the server and kill the instance of the service, then restart the service by

1.) logging into putty
2.) typing in 'vncserver'
3.) log into the server thru the client

I have full admin privileges. I still have to access some stuff as superuser, but I can open just about everything, even open an explorer window and log in as super user.
vncserverservice-1.jpg
vncserverservice-1.jpg (108.01 KiB) Viewed 892 times
If I have the systemd service start the vncserver then I cannot access the same stuff and it seems I do not have the same user privileges. Does anyone know how to fix this?

lazlo
Posts: 112
Joined: Sun Oct 01, 2017 11:32 am
languages_spoken: english
ODROIDs: XU4
Contact:

Re: Start VNC server at boot or restart

Unread post by lazlo » Wed Nov 21, 2018 2:28 pm

If you have logged in to X as root that is bad. It could be very bad.

Please check "ls -al /path/to/your/home/dir" and if you see any files owned by root run "chown -R yourusename:yourusername /path/to/your/home/dir/*" and then "chown -R yourusename:yourusername /path/to/your/home/dir/*.*" and that should take care of any permissions issues.

You can have lightdm start the VNC server when it starts. Doing this is useful in a multi-user environment because it allows 2 people (or more, depending on the configuration) to log in at once. You will need to edit lightdm.conf to enable this and might need to edit your vnc server config file if you want the connection to only work via ssh (I have never tried it over ssh with lightdm, so I am not sure if I can give solid advice about setting it up right.). Just be aware that if you are not using ssh then everything typed in is being sent as across your network as clear text. This includes passwords.

EDIT: I just want to add that any issues you have with the system outside of the /home directory because you logged in to an X session as root may be non-trivial to fix.

dstair
Posts: 41
Joined: Sun Oct 22, 2017 1:21 am
languages_spoken: english
ODROIDs: XU4, HC1, HC2, MC1
Location: United States, Indiana
Contact:

Re: Start VNC server at boot or restart

Unread post by dstair » Thu Nov 22, 2018 9:55 am

I have not been logging in as root for sure. I tried that when I first set it up, and it did not even function correctly. You have to be logged in as a user. What has me baffled is when I start the VNC service using putty then log on to the server thru the client it works fine. But it is when I enable the service using systemd it has permissions issues when I log on thru the client. I am not understanding how changing permissions on any of the folders will make it work for the instance where I am having trouble.

lazlo
Posts: 112
Joined: Sun Oct 01, 2017 11:32 am
languages_spoken: english
ODROIDs: XU4
Contact:

Re: Start VNC server at boot or restart

Unread post by lazlo » Thu Nov 22, 2018 1:01 pm

The most obviously change in permissions I can think of would be that systemd is running the daemon as a different user then when you start it by hand. It could also be that systemd starting the process causes it gain permissions or restrictions but starting it by hand does not or it could be the other way around. First check ownership of the process in both cases (top would do nicely) and see if there is a difference.

dstair
Posts: 41
Joined: Sun Oct 22, 2017 1:21 am
languages_spoken: english
ODROIDs: XU4, HC1, HC2, MC1
Location: United States, Indiana
Contact:

Re: Start VNC server at boot or restart

Unread post by dstair » Tue Nov 27, 2018 12:43 pm

Well, I found out I needed to remove most of the stuff in the Unit section and that I needed to simply add the line

PAMName=login

under Service

Then change the line

PIDFile=/home/'username'/.vnc/%H:%i.pid

to

PIDFile=/home/%u/.vnc/%H:%i.pid


Funny thing is this works and I can start and kill the VNC service, log in and do everything I want to do, but when I start the service I get the message that starting the service failed. Here is the message

Job for vncserver@1.service failed because the service did not take the steps required by its unit configuration.
See "systemctl status vncserver@1.service" and "journalctl -xe" for details.

Then when I enter "systemctl status vncserver@1.service" I get

vncserver@1.service - Systemd VNC server startup for HC2
Loaded: loaded (/etc/systemd/system/vncserver@.service; indirect; vendor preset: enabled)
Active: failed (Result: protocol) since Mon 2018-11-26 22:34:37 EST; 3min 32s ago

Nov 26 22:34:34 HC2-Svr systemd[1]: Starting Systemd VNC server startup for HC2...
Nov 26 22:34:34 HC2-Svr systemd[30053]: pam_unix(login:session): session opened for user 'user' by (uid=0)
Nov 26 22:34:34 HC2-Svr systemd[30059]: pam_unix(login:session): session opened for user 'user' by (uid=0)
Nov 26 22:34:37 HC2-Svr systemd[1]: vncserver@1.service: Can't open PID file /home/root/.vnc/HC2-Svr:1.pid (yet?) after start: No such file or directory
Nov 26 22:34:37 HC2-Svr systemd[1]: vncserver@1.service: Failed with result 'protocol'.
Nov 26 22:34:37 HC2-Svr systemd[1]: Failed to start Systemd VNC server startup for HC2.

Is this normal?
Last edited by dstair on Thu Nov 29, 2018 10:37 am, edited 1 time in total.

dstair
Posts: 41
Joined: Sun Oct 22, 2017 1:21 am
languages_spoken: english
ODROIDs: XU4, HC1, HC2, MC1
Location: United States, Indiana
Contact:

Re: Start VNC server at boot or restart

Unread post by dstair » Tue Nov 27, 2018 12:50 pm

So, I ended up with this as the systemd .service file

# /etc/systemd/system/vncserver@.service

[Unit]
Description=Systemd VNC server startup for HC2
After=syslog.target network.target

[Service]
Type=forking
User='username'
PAMName=login
PIDFile=/home/%u/.vnc/%H:%i.pid
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :'
ExecStart=/usr/bin/vncserver -depth 24 -geometry 1920x1080 :%i
ExecStop=/usr/bin/vncserver -kill :%i

[Install]
WantedBy=multi-user.target

dstair
Posts: 41
Joined: Sun Oct 22, 2017 1:21 am
languages_spoken: english
ODROIDs: XU4, HC1, HC2, MC1
Location: United States, Indiana
Contact:

Re: Start VNC server at boot or restart

Unread post by dstair » Thu Nov 29, 2018 10:39 am

Does anyone know what the error lines mean from above when I checked the status of my vnc server?

Active: failed (Result: protocol)

and

Failed to start Systemd VNC server startup for HC2

But I was able to log into the server. Do I have something set up incorrectly?

nn_m
Posts: 8
Joined: Thu Aug 02, 2018 3:07 am
languages_spoken: english
ODROIDs: XU4
Contact:

Re: Start VNC server at boot or restart

Unread post by nn_m » Mon Feb 11, 2019 11:13 pm

Hi @dstair,
dstair wrote:
Tue Nov 27, 2018 12:50 pm
So, I ended up with this as the systemd .service file
.....
Thanks very much for sharing your experience and hard work! I'm hoping this will work for me, as I would really like VNC access to XU4.

---------
I have no real experience with systemd, but given the discussion of root ownership above, does the fact that /home/root is mentioned in the error message indicate a source of your problem?
dstair wrote:
Tue Nov 27, 2018 12:43 pm

Code: Select all

.....
   Active: failed (Result: protocol) since Mon 2018-11-26 22:34:37 EST; 3min 32s ago

....
Nov 26 22:34:34 HC2-Svr systemd[30059]: pam_unix(login:session): session opened for user 'user' by (uid=0)
Nov 26 22:34:37 HC2-Svr systemd[1]: vncserver@1.service: Can't open PID file /home/root/.vnc/HC2-Svr:1.pid (yet?) after start: No such file or directory
....
Is this normal?
Thanks again for posting your progress, and good luck

User avatar
meveric
Posts: 9714
Joined: Mon Feb 25, 2013 2:41 pm
languages_spoken: german, english
ODROIDs: X2, U2, U3, XU-Lite, XU3, XU3-Lite, C1, XU4, C2, C1+, XU4Q, HC1, N1, Go
Contact:

Re: Start VNC server at boot or restart

Unread post by meveric » Tue Feb 12, 2019 3:56 am

nn_m wrote:
Mon Feb 11, 2019 11:13 pm
Thanks very much for sharing your experience and hard work! I'm hoping this will work for me, as I would really like VNC access to XU4.
There are several different VNC servers which are more or less easy to configure and offer different kind of performance and capabilities.
I for example prefer vino as a VNC server which works perfectly fine for me and which I start only when I need it remotely.
It directly attaches to the user session so you don't have to create a new virtual session/desktop that runs aside of the desktop of your user, but instead uses the same session your user's desktop is running on.
nn_m wrote:
Mon Feb 11, 2019 11:13 pm
I have no real experience with systemd, but given the discussion of root ownership above, does the fact that /home/root is mentioned in the error message indicate a source of your problem?
If you check the code you find the following section:
dstair wrote:
Tue Nov 27, 2018 12:50 pm
PIDFile=/home/%u/.vnc/%H:%i.pid
/home/%u (user) exists for normal users such as odroid, but the home folder of the user "root" is not /home/root/ but /root/ that is why this is failing if you start the service as user ROOT.
It's probably best to forbit root to run this service at all, as it's potentially harmful as the VNC server and with that the desktop you run, should NOT run as the user root, as this is a very high security risk.
Donate to support my work on the ODROID GameStation Turbo Image for U2/U3 XU3/XU4 X2 X C1 as well as many other releases.
Check out the Games and Emulators section to find some of my work or check the files in my repository to find the software i build for ODROIDs.
If you want to add my repository to your image read my HOWTO integrate my repo into your image.

nn_m
Posts: 8
Joined: Thu Aug 02, 2018 3:07 am
languages_spoken: english
ODROIDs: XU4
Contact:

Re: Start VNC server at boot or restart

Unread post by nn_m » Sat Feb 16, 2019 2:49 pm

@meveric . Thanks again for your help!

Incidentally per my previous post, I reloaded stretch, rebooted my windows PC and then everything just started working.
In a similar vein, when I tried to install Chromium per your instructions, I was getting core-dumps when I ran the program, but a few days later uninstalled and reinstalled and now its working! I'm still getting error messages, but chromium now starts up and is usable.

But, regarding installing VNC and vino, is
viewtopic.php?f=52&t=15320&p=99651
the best set of instructions that will work on XU4 with Stretch?

II've install vino, and dconf-editor
but get "no command' for vino-preferences and dconf
(per the commands in that article). (With, or without sudo prefixed).

I did search for 'debian install vnc vino', but those ubuntu directions seemed the best.

Thanks for any help

User avatar
meveric
Posts: 9714
Joined: Mon Feb 25, 2013 2:41 pm
languages_spoken: german, english
ODROIDs: X2, U2, U3, XU-Lite, XU3, XU3-Lite, C1, XU4, C2, C1+, XU4Q, HC1, N1, Go
Contact:

Re: Start VNC server at boot or restart

Unread post by meveric » Sat Feb 16, 2019 5:31 pm

nn_m wrote:
Sat Feb 16, 2019 2:49 pm
@meveric . Thanks again for your help!

Incidentally per my previous post, I reloaded stretch, rebooted my windows PC and then everything just started working.
In a similar vein, when I tried to install Chromium per your instructions, I was getting core-dumps when I ran the program, but a few days later uninstalled and reinstalled and now its working! I'm still getting error messages, but chromium now starts up and is usable.
For a long time now running Chromium latest version on armhf was causing issues. Ubuntu Version apparently fixed this, but Debian was still broken.
I backported Chromium 63 as this was the last version that was working properly and put it in my repository.
I mentioned several times on the forum how to install it.
If latest version of Chromium is finally working again, that's even better :)
nn_m wrote:
Sat Feb 16, 2019 2:49 pm
But, regarding installing VNC and vino, is
viewtopic.php?f=52&t=15320&p=99651
the best set of instructions that will work on XU4 with Stretch?
Sadly no, as Ubuntu deliberately keeps an old version of vino due to the fact that vino-preferences was removed in later versions, Which you already figured out yourself.
Here's what you can do:

# Installation:

Code: Select all

apt-get install vino
# Manual start (can be done over ssh):

Code: Select all

DISPLAY=:0 /usr/lib/vino/vino-server
Please Note: this must be run as the same user that is logged into the Desktop, as it's using the Desktop session of that user.
This of cause also means you need to have a desktop installed and the user needs to be logged in.

# Configuration:
Per default vino shows a prompt on the desktop saying that someone tries to connect and if this should be allowed. Normally you're not sitting in front of the PC when you want to remote control it, so it's best to deactivate this setting (can be done remotely via ssh with the DISPLAY=:0 option also running as the desktop user)

Code: Select all

DISPLAY=:0 gsettings set org.gnome.Vino prompt-enabled false
Some Windows clients (like Ultra VNC) have issues with the encryption so you probably need to disable encryption for these clients:

Code: Select all

DISPLAY=:0 gsettings set org.gnome.Vino require-encryption false
This should allow you to remote connect to your ODROID without a password, if you think this is to insecure, you can setup your own password like this:

Code: Select all

DISPLAY=:0 gsettings set org.gnome.Vino require-encryption $(echo -n "mypassword"|base64)
DISPLAY=:0 gsettings set org.gnome.Vino authentication-methods "['vnc']"
I'm not 100% sure but in the past some clients only supported passwords up to 8 characters, but this could be old info, just keep that in mind in case your password doesn't work.

# Autostart
If you want vino to start always when your ODROID is started (auto login of user required).
You can create a vino.desktop file that you put in ~/.config/autostart/ (create the folder if it does not yet exist) with the following content:

Code: Select all

[Desktop Entry]
Type=Application
Name=Vino VNC server
Exec=/usr/lib/vino/vino-server
NoDisplay=true
Donate to support my work on the ODROID GameStation Turbo Image for U2/U3 XU3/XU4 X2 X C1 as well as many other releases.
Check out the Games and Emulators section to find some of my work or check the files in my repository to find the software i build for ODROIDs.
If you want to add my repository to your image read my HOWTO integrate my repo into your image.

pat2
Posts: 37
Joined: Sun Jan 06, 2019 2:22 am
languages_spoken: english
ODROIDs: XU4Q
Contact:

Re: Start VNC server at boot or restart

Unread post by pat2 » Sun Feb 17, 2019 10:53 pm

I installed VNC server at boot (or at restart) on Odroid XU4 on 16.04 (or 18.04) images provided by Hardkernel.
They are working. Follow instructions at:

for 18.04: https://www.digitalocean.com/community/ ... untu-18-04
for 16.04: https://www.digitalocean.com/community/ ... untu-16-04

There is a little difference between 18.04 and 16.04in the VNC service file.

you have to install NOT as root!

To test: skip step 3. Test directly with a VNC client (e.g.: real vnc on windows) on another PC calling the server at: server_IP:5901 (e.g. 192.168.1.198:5901)

lazlo
Posts: 112
Joined: Sun Oct 01, 2017 11:32 am
languages_spoken: english
ODROIDs: XU4
Contact:

Re: Start VNC server at boot or restart

Unread post by lazlo » Mon Feb 18, 2019 3:29 am

If you are using lightdm on your system then you can use it so start the VNC server. Just add the following to your lightdm.conf file:

Code: Select all

[VNCServer]
enabled=true
command=Xvnc	#This should work with almost all VNC servers but you need to add -rfbauth and other options may be needed.
port=5900
listen-address=		#Set this to localhost for ssh tunneling or comment it out if you don't mind insecure transmission of data.
width=1920
height=1080
depth=24
As long you have a VNC server installed and these lines in your lightdm.conf file then lightdm will start the VNC server after it finishes loading. I like to use it because it will allow multiple users to be logged in to the system at the same time and they will all get their own sessions and desktops.

dstair
Posts: 41
Joined: Sun Oct 22, 2017 1:21 am
languages_spoken: english
ODROIDs: XU4, HC1, HC2, MC1
Location: United States, Indiana
Contact:

Re: Start VNC server at boot or restart

Unread post by dstair » Mon Feb 18, 2019 6:23 am

meveric wrote:
Tue Feb 12, 2019 3:56 am
nn_m wrote:
Mon Feb 11, 2019 11:13 pm

If you check the code you find the following section:
dstair wrote:
Tue Nov 27, 2018 12:50 pm
PIDFile=/home/%u/.vnc/%H:%i.pid
/home/%u (user) exists for normal users such as odroid, but the home folder of the user "root" is not /home/root/ but /root/ that is why this is failing if you start the service as user ROOT.
It's probably best to forbit root to run this service at all, as it's potentially harmful as the VNC server and with that the desktop you run, should NOT run as the user root, as this is a very high security risk.
I am not quite understanding what you were saying. is the line "PIDFile=/home/%u/.vnc/%H:%i.pid" incorrect? It sounds like you are saying that I am starting the service as ROOT, but my intent is to start the service as a standard user. I have run vnc as root before to observe the differences between root and a standard user. This being said, currently when the system starts using Systemd it appears as it has been started with a user profile.
The problem: not all of the superuser functioality is available when vnc starts with SystemD on startup or reboot. Specifically, if I open a file system browser window and right click on a file I should be able to select "open as administrator" but that line is grayed out. Hopefully that adequately explained what the issue was / is.
If I have the service file setup incorrectly (starting the service as ROOT), can you please point me in the right direction, --> how to start the service as a standard user and not ROOT.

User avatar
meveric
Posts: 9714
Joined: Mon Feb 25, 2013 2:41 pm
languages_spoken: german, english
ODROIDs: X2, U2, U3, XU-Lite, XU3, XU3-Lite, C1, XU4, C2, C1+, XU4Q, HC1, N1, Go
Contact:

Re: Start VNC server at boot or restart

Unread post by meveric » Mon Feb 18, 2019 6:54 am

dstair wrote:
Mon Feb 18, 2019 6:23 am
I am not quite understanding what you were saying. is the line "PIDFile=/home/%u/.vnc/%H:%i.pid" incorrect? It sounds like you are saying that I am starting the service as ROOT, but my intent is to start the service as a standard user.
I was referring to the following error:
dstair wrote:
Tue Nov 27, 2018 12:43 pm

Code: Select all

....
Nov 26 22:34:34 HC2-Svr systemd[30059]: pam_unix(login:session): session opened for user 'user' by (uid=0)
Nov 26 22:34:37 HC2-Svr systemd[1]: vncserver@1.service: Can't open PID file /home/root/.vnc/HC2-Svr:1.pid (yet?) after start: No such file or directory
....
The error shows "/home/root/.vnc/HC2-Svr:1.pid" so obviously the "%u" in PIDFile=/home/%u/.vnc/%H:%i.pid was replaced with "root" which seems to indicate that it was run with user "root" and not with a regular user.
dstair wrote:
Mon Feb 18, 2019 6:23 am
If I have the service file setup incorrectly (starting the service as ROOT), can you please point me in the right direction, --> how to start the service as a standard user and not ROOT.
The file looks ok, as I said, I would just prevent root from starting the file add a check if `username` is root or uid = 0 if so then do not start the service.
That's all.
Donate to support my work on the ODROID GameStation Turbo Image for U2/U3 XU3/XU4 X2 X C1 as well as many other releases.
Check out the Games and Emulators section to find some of my work or check the files in my repository to find the software i build for ODROIDs.
If you want to add my repository to your image read my HOWTO integrate my repo into your image.

dstair
Posts: 41
Joined: Sun Oct 22, 2017 1:21 am
languages_spoken: english
ODROIDs: XU4, HC1, HC2, MC1
Location: United States, Indiana
Contact:

Re: Start VNC server at boot or restart

Unread post by dstair » Mon Feb 18, 2019 7:43 am

meveric wrote:
Mon Feb 18, 2019 6:54 am
dstair wrote:
Mon Feb 18, 2019 6:23 am
I am not quite understanding what you were saying. is the line "PIDFile=/home/%u/.vnc/%H:%i.pid" incorrect? It sounds like you are saying that I am starting the service as ROOT, but my intent is to start the service as a standard user.
I was referring to the following error:
dstair wrote:
Tue Nov 27, 2018 12:43 pm

Code: Select all

....
Nov 26 22:34:34 HC2-Svr systemd[30059]: pam_unix(login:session): session opened for user 'user' by (uid=0)
Nov 26 22:34:37 HC2-Svr systemd[1]: vncserver@1.service: Can't open PID file /home/root/.vnc/HC2-Svr:1.pid (yet?) after start: No such file or directory
....
The error shows "/home/root/.vnc/HC2-Svr:1.pid" so obviously the "%u" in PIDFile=/home/%u/.vnc/%H:%i.pid was replaced with "root" which seems to indicate that it was run with user "root" and not with a regular user.
dstair wrote:
Mon Feb 18, 2019 6:23 am
If I have the service file setup incorrectly (starting the service as ROOT), can you please point me in the right direction, --> how to start the service as a standard user and not ROOT.
The file looks ok, as I said, I would just prevent root from starting the file add a check if `username` is root or uid = 0 if so then do not start the service.
That's all.
question 1: Where would I put this check?
Can you write an example of the syntax? I am familiar with a C code if statement, just not how to format it for a systemd service lol

User avatar
meveric
Posts: 9714
Joined: Mon Feb 25, 2013 2:41 pm
languages_spoken: german, english
ODROIDs: X2, U2, U3, XU-Lite, XU3, XU3-Lite, C1, XU4, C2, C1+, XU4Q, HC1, N1, Go
Contact:

Re: Start VNC server at boot or restart

Unread post by meveric » Mon Feb 18, 2019 7:50 am

The easiest way is to replace ExecStart=/usr/bin/vncserver -depth 24 -geometry 1920x1080 :%i
with a script:
ExecStart=/usr/local/bin/start_vnc_server.sh
then copy your command over into that script and add the check:

Code: Select all

#!/bin/bash
if [ $UID -ne 0 ]; then
  /usr/bin/vncserver -depth 24 -geometry 1920x1080 :%i
else
  echo "do not run as root!"
  exit 1
fi
That way you can use the script for other things later if need be.. like loading config files and take values from there or something like that.
Donate to support my work on the ODROID GameStation Turbo Image for U2/U3 XU3/XU4 X2 X C1 as well as many other releases.
Check out the Games and Emulators section to find some of my work or check the files in my repository to find the software i build for ODROIDs.
If you want to add my repository to your image read my HOWTO integrate my repo into your image.

Post Reply

Return to “Ubuntu”

Who is online

Users browsing this forum: No registered users and 9 guests