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 Desktop gconftool-2 -s -t bool /desktop/gnome/remote_access/enabled true</pre>stopvnc.sh#!/bin/bash # # This script starts enables System -> Preferences -> Remote Desktop gconftool-2 -s -t bool /desktop/gnome/remote_access/enabled false</pre>After creating those scripts, I make them executable with this command:$ chmod +x startvnc.sh $ chmod +x stopvnc.shI 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</pre>Now, when you SSH into your box (or open a command line), you can just type$ startvncto enable Remote Desktop, or$ stopvncto 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).
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!
[...] true but it only works when I do alt+f2 I got it from this website: Ubuntu 7.04 – Enable/Disable Remote Desktop from the Command Line So it [...]
Your code haven’t work on Ubuntu 8.04
“”"bash: gconftool-2: command not found”"”"
what do??? please help
I checked ubuntu 8.04 and 8.10 and it works. Check that you have access to /usr/bin/gconftool-2. And here is a script to combine everything into one simple script
#!/bin/bash
#
# name: cfg_remote_desk.sh
#
#
case “$1″ in
start)
gconftool-2 -s -t bool /desktop/gnome/remote_access/enabled true
gconftool-2 -s -t bool /desktop/gnome/remote_access/prompt_enabled false
echo “Remote Access Enabled”
;;
stop)
gconftool-2 -s -t bool /desktop/gnome/remote_access/enabled false
echo “Remote Access Disabled”
;;
*)
echo “Usage $0 start|stop ”
;;
esac
Hi, thanks for post. Actualy this methosd works for me only if I am connected locally. It is NOT working through SSH from remote machine.
One important thing to mention – VNC is not secure protocol and you have to tunnel it through SSH.
Thanks very much,
It really worked for me.
Does anyone have documentation for secure vnc? I am using RHEL 5. Any help will be appreciated. Thanks
I can confirm the comment from Lex – I too cannot disable Remote Access via SSH. When I run “gconftool-2 -s -t bool /desktop/gnome/remote_access/enabled false” from a PuTTY SSH session on my Windows PC it doesn’t complain and even returns “false” when I enter “gconftool-2 -g /desktop/gnome/remote_access/enabled” but I can still use VNC to connect (via the SSH tunnel). Interestingly the same time my Windows SSH session reports the enabled status as “false” a terminal session on my Ubuntu machine returns “true”. I don’t if you or anyone can help but I’d be mighty grateful, as this would be a simple and elegant solution for me. Thanks.
both works in my box (RHEL 5.3).
1. But what if I want to include/require the password. What command should I use? $ gconftool-2 -s -t bool /desktop/gnome/remote_access/prompt_enable true
/* this ask permission only, but does not require password */
2. I want to allow the user to control also the desktop, what command should I use? $ gconftool-2 -s -t bool /desktop/gnome/remote_access/enabled true /* allow only to view, but not control */
Appreciate your help.
Thanks,
Jay
I can also confirm Lex and Craig’s comments. Disabling Remote Access using gconftool over SSH does not work anymore. It used to work a few Ubuntu releases ago, but it doesn’t work in 8.10, 9.04, (maybe even 8.04, but I can’t remember).
Is there anyway to get this to work again? Thanks.
I happened to solve my own problem. See http://ubuntuforums.org/showthread.php?p=7401969 for more details and a script to toggle remote desktop on and off. Basically, you have to run ‘dbus-launch gconftool …’.
Hi,
This is a good explanation. I was looking fr this kind of explanation. Thanks buddy it helped me alot.
Sorry to disagree with the poster, but the two command most certainly do not work with Ubuntu 8.10. I have tried them with two machines on my local LAN and the commands do absolutely nothing.
Not only has the commands to enable vnc via ssh not worked, it appears to have done more than that, it has broken completely remote desktop on my ubuntu 8.10 system.
I deleted the menu shortcut in gnome
System>Preferences>”Remote Desktop Preferences”
How do I restore the link..
Crazy I know…
Thanks









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