Ubuntu 7.04 - Enable/Disable Remote Desktop from the Command Line
First, enable Remote Desktop in Gnome by going to System -> Preferences -> Remote Desktop.
Check ‘Allow other users to view your desktop’.
Check ‘Allow other users to control your desktop’.
Uncheck ‘Ask you for confirmation’.
Type in the password you want to use.
Click Close.
Remote Desktop is now running on your machine.
Now, open a terminal and type this command:
$ gconftool-2 -s -t bool /desktop/gnome/remote_access/enabled false
Go back to System -> Preferences -> Remote Desktop. You will see that it is now turned off.
You can turn it back on from the command line using this command:
$ gconftool-2 -s -t bool /desktop/gnome/remote_access/enabled true
The reason I find these commands handy is that I like to only turn on Remote Desktop when I actually need to use it. So, after I set up SSH and secure it, I then log into my machine remotely via SSH and run the command to enable Remote Desktop. Once I do that, I can then open up VNC Viewer from the remote machine, and do what I need to do. I then disable Remote Desktop via SSH with the disable command so that the server is no longer available to myself or anyone else that might try to access it.
I have taken this a step further on my machine and simplified this process by creating two bash shell scripts:
startvnc.sh
#!/bin/bash
#
# This script starts enables System -> Preferences -> Remote Desktopgconftool-2 -s -t bool /desktop/gnome/remote_access/enabled true
stopvnc.sh
#!/bin/bash
#
# This script starts enables System -> Preferences -> Remote Desktopgconftool-2 -s -t bool /desktop/gnome/remote_access/enabled false
After creating those scripts, I make them executable with this command:
$ chmod +x startvnc.sh
$ chmod +x stopvnc.sh
I then make aliases to them. Open ~/.bashrc in a text editor, scroll to the bottom, and type in these two lines:
alias startvnc=/path/to/your/startvnc.sh
alias stopvnc=/path/to/your/stopvnc.sh
Now, when you SSH into your box (or open a command line), you can just type $ startvnc to enable Remote Desktop, or $ stopvnc to disable Remote Desktop.
*Remember, if you are behind a firewall, you have to allow access through port 5900 if you want to Remote Desktop into your default display (:0).
If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.
Comments
Sam
May i know how the same configurations can be done thru command line in KDE?
I have SuSe Linux 8.1 with KDE3 installed on it?
Thanks
Venkatesh
Nice it works in ubuntu for me ! very nice because i only have SSH login to it but now i have full control. Thx
[...] Sam Lesher » Ubuntu 7.04 - Enable/Disable Remote Desktop from the Command Line To enable remote desktop from the command line, issue this command: [...]
Hi Sam,
Thanks for a great work, inorder to enable remote access by using this command below.
[root@localhost ~]# gconftool-2 -s -t bool /desktop/gnome/remote_access/enabled true
But with the same command how can we disable SECURITY option Ask you for confirmation
please help and respond
Regards,
K.S.NAIDU
To disable SECURITY option (Ask you for confirmation), use this command:
gconftool-2 -s -t bool /desktop/gnome/remote_access/prompt_enabled false
Hi Sam.
This is pretty top - but I have no graphical access to my Ubuntu desktop. Any way to crowbar the initial setup (System -> Preferences -> Remote Desktop) or do I have to put a head back on it? I realise I should have enabled this at install, but I didn’t! Do you know where the config files are?
And I’m running Hardy too so none of this may be relevant
Cheers for a fine article either way!
Sussed!
Of course, not only did I not have remote desktop enabled, I also wasn’t logged in at the console. I knife and forked it by installing tightvncserver and starting a new graphical head through there. Then I used gdmsetup to allow me autologin.
Now I’m *really* glad I found this page. Thank you Sam!









Sam
Greetings.Really great work. It’s very handy so that i can enable such an option on a remote Linux machine which has no GUI access. Really happy with it.
Thank You Very Much
Regards
Venkatesh