ls: cannot access .gvfs: Permission denied
Running graphical applications with sudo
can sometimes lead to problems like this.
Explanation
sudo
runs the program with superuser privileges (like running as root), but the program still sees the current home directory as your home directory.
So, when the software writes its configuration files, it'll end up creating files in your home directory that are owned by the root user. You end up with files you yourself cannot edit or delete, and software running as you won't be able to modify it either, leading to more problems.
What is the best solution?
There is an alternative: gksudo
.
This variant of sudo will set up environment variables, such as the home directory, in such a way that makes running graphical applications as root a lot safer and won't confuse programs into creating root-owned files in your home directory.
Why does this affect graphical applications?
This doesn't just affect graphical applications, nor does it affect all graphical applications. It affects applications that store configuration inside the current user's home directory. This is just more common among graphical applications.
Sometimes applications will be able to detect if they're run with sudo and adjust their behaviour accordingly, but this is not common with graphical applications which are usually not expected to be run with sudo.
How do I fix the problem?
You'll need to find root-owned files and directories within your home directory and remove them. It's better to remove them than change their ownership in my opinion, as they were not intended for your user, but the root user, so there may be unexpected effects if you simply change ownership. You can of course back them up in case you decide there's something you want in them later.
To find root-owned files in your home directory:
find ~ -user root
If you are still having problems with some applications (run as your user), try rebooting to clear out /tmp
and anything still running. Occasionally some applications might have corrupted their existing config files and need you to remove all their configuration in your home directory, but hopefully this won't be the case for many.
Just give the user permissions to the .gvfs/
and it should fix it.
sudo chown -R $USER:$USER ~/.gvfs/