Enable remote desktop for Gnome from command line?

I am trying to set up some automation scripts to set up a Linux environment. I would like to enable remote desktop sharing without the user having to actually use the GUI to do so. My plan is to write a batch script that maybe edits some file to do this automatically, if possible.

I am using Fedora 16 with the Gnome.

I want to achieve the following:
http://docs.fedoraproject.org/en-US/Fedora/13/html/User_Guide/chap-User_Guide-Sharing_your_desktop.html

Any tips on what file to edit would be greatly appreciated.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

If I understand you right: you want to share gnome or other environment remotely as it is, then the easiest way to achieve this is to use x11vnc. It shares real X11 server as it is after user logged in:

x11vnc -display :0

Or if you want vnc server run after login, you can automate with this script:

#!/bin/bash
/usr/bin/x11vnc -nap -wait 50 -noxdamage -passwd PASSWORD -display :0 -forever -o /var/log/x11vnc.log -bg

You can place this script in startup programs in gnome, so that it could be run automatically when the user logins. Please note that this script is not secure as session PASSWORD variable is clearly seen to anyone who could read the file and anyone knowing password can connect to vnc session (password in this case is 8 symbols word asked when you are connecting remotely). If you want more secure connection search how to do vnc ssh tunneling.

Method 2

My favorite method for remote connections is to use vino. It’s similar to x11vnc, but I find it much easier to set up (though I’m typically using a GUI). With Vino enabled, gnome is set up to accept vnc connections for the active session (the one that is currently logged in), for every boot. Any windows or applications open on the screen will be viewable in the vnc connection.

In normal cases (e.g., through a GUI), it’s enough to set it up by running

$ vino-preferences

In the absence of a GUI, the settings must be changed using gsettings. Something like

$ gsettings set org.gnome.Vino enabled true
$ gsettings set org.gnome.Vino view-only true
$ gsettings set org.gnome.Vino authentication-methods "['vnc']"
$ gsettings set org.gnome.Vino prompt-enabled false
$ gsettings set org.gnome.Vino require-encryption true

would enable remote desktop with sane values. You can see the full list of options as well as a description of their effects by opening dconf-editor and navigating to desktop.gnome.remote-access.

If your computer has multiple users, Vino will need to be set up for each user.


To connect to your remote session, you can use any standard vnc client. However, you must forward port 5900 to the computer you want to connect to from your router’s firmware. Alternatively, if you are also allowing for ssh connections to these computers, it may be easier and more secure to use vnc through an ssh tunnel. From your local machine:

ssh -L 5900:localhost:5900 <remote server>

Then open up a vnc client and connect to 127.0.0.1:5900 and log in with your remote server’s username and password.

Method 3

I was able to set a fresh Ubuntu 16.04 install from a remote ssh connection with the following script:

#!/bin/bash
export DISPLAY=:0
read -e -p "VNC Password: " -i "ubuntu" password
dconf write /org/gnome/desktop/remote-access/enabled true
dconf write /org/gnome/desktop/remote-access/prompt-enabled false
dconf write /org/gnome/desktop/remote-access/authentication-methods "['vnc']"
dconf write /org/gnome/desktop/remote-access/require-encryption false
dconf write /org/gnome/desktop/remote-access/vnc-password "'$(echo -n $password | base64)'"
dconf dump /org/gnome/desktop/remote-access/
sudo service lightdm restart

The quoting is important for any of the string settings (single ticks inside quotes).

For dconf to be able to write it needs access to XWindows, so that’s why the export DISPLAY part is needed. I think you still need to be logged in to the desktop on the actual Ubuntu machine to connect with VNC after this.

The dump command is just there to confirm all the settings took hold, you don’t really need that.

Method 4

If I need access to my desktop I generally just SSH in and run “x11vnc” and then connect w/ VNC.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x