6

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.

9

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.

  • Any idea how to get that running on GDM in case the machine isn't already logged in? – LVLAaron Apr 20 '13 at 19:33
  • You can do that too: x11vnc -display :0 -auth /var/lib/gdm/:0.Xauth – IBr Apr 20 '13 at 20:24
  • Is there a way to do this just once without placing any scripts in startup? When I enable desktop sharing, I only have to do it once after I am setting up the machine. That would be great. Thanks! – M S Apr 21 '13 at 5:52
  • Connect with ssh to pc you want and just run x11vnc from terminal if you are already logged in (for example after setup your PC restarted and you got autologin, then you could run ssh to connect to it type in terminal x11vnc -display :0 and you are free to connect with any client you want. Or either you can connect with ssh at any time and run x11vnc -display :0 -auth /var/lib/gdm/:0.Xauth to connect directly to gdm login screen). After you're done, you can stop x11vnc and disconnect from ssh. – IBr Apr 21 '13 at 6:13
6

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.

  • 1
    Unlike the x11vnc answers, this is how to get remote access to the :0 that you left at work. Now that wasn't the OP's question, but it was mine, so thanks! – Martin Dorey Apr 16 '14 at 3:11
1

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

1

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.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.