Firefox only runs with `sudo`

14,989

Solution 1

You have configuration files in your home directory that you don't have access to.

This is a result of running sudo on programs using your personal space. Sudo should only be run when you are intentionally making system wide changes on the system.

You can verify this with:
(I would discourage using sudo in your personal space. You can find files and folders that are not owned by your account without elevated access. If no output, there no need to run sudo. Some users mightnot even have sudo access, and would get a warning and notice to the administrator just by testing it.)

$ find ~/ -mount ! -user $(whoami)

You can correct this with:

$ sudo chown -R $(whoami):$(whoami) ~/

Note:

The problem you are having in this case is your Firefox application. You are noticing it because you find you are loosing functionality because of this problem. Taking ownership of all the personal files in your space may correct other problems that you are having, but haven't identified yet.

It's customary to use a space outside of your home folder for files with permission outside of your own ownership. A conventional place to put those files is in /opt, or /usr/local/bin for executional. It's unlikely that you will break your system by owning your files in your home folder. It is likely that some components may be broken by you not owning files in your home space.

Running sudo is the culprit of many problems, and should be run with care.

Solution 2

Although it's probably fine to (re)take ownership of everything in your home directory, the specific reason you were unable to start Firefox is that your Firefox profile was inaccessible when you didn't run firefox with sudo.Therefore, I recommend retaking ownership of just the folder that contains your Firefox profile and other user-specific Firefox data (like your Firefox extensions):

sudo chown -R $USER:$USER ~/.mozilla

That will work if you enter it exactly as written. Or, if you like, you can replace $USER with your username. If you do that, make sure you do not keep the $.

(You may also use $(whoami):$(whoami) instead of $USER:$USER, as in L.D. James's answer, if you want.)

Make sure Firefox is not running when you execute that command.

Then open Firefox. It should run, now.


Your problem was most likely caused by running Firefox with sudo in the first place. In the case of a program like Firefox, you should just not run it as root -- there is never really any situation where it would be useful to do so.

In general, however, if you find you must run a graphical application as root, you should almost never use plain sudo for that, since it causes any configuration files the application creates to be owned by the root user but still be created in your home directory rather than root's.

Instead, you can use gksu, gksudo, kdesudo (on Kubuntu), sudo -H, or sudo -i when you encounter a situation where you must run a graphical program as root. However, I emphasize that running programs as root is for system administration. You might decide to run a text editor as root to edit the system's configuration files, but you never need to, and never should, run a program like a web browser or word processor as root.

Share:
14,989

Related videos on Youtube

Nirghum Di-prohor
Author by

Nirghum Di-prohor

Updated on September 18, 2022

Comments

  • Nirghum Di-prohor
    Nirghum Di-prohor over 1 year

    I have to run sudo firefox to open my Firefox browser. If I try to open it normally it doesn't work.

    When I do not use sudo, the error message is:

    Your Firefox profile cannot be loaded, it may be missing or inaccessible.

    The output of the command itself is Permission denied. This is with Firefox 50.1.0. How to fix it?

    • Nirghum Di-prohor
      Nirghum Di-prohor over 7 years
      Thanks for reply. The error message is : "Your Firefox profile cannot be loaded, it may be missing or inaccessible. " Firefox version is : 50.1.0 and the output of the command is "Permission denied".
  • Rinzwind
    Rinzwind about 7 years
    My edit is correct... your command will error out on gvfs. find . -mount ! -user $USER ./.gvfs find: ./.gvfs': Permission denied ./.config/enchant find: ./.config/enchant': Permission denied ./.dbus find: ./.dbus': Permission denied ./.cache/dconf find: ./.cache/dconf': Permission denied` Making newbie users ask questions. Plus it would also error out on ".mozilla" if owned by root. In this case using sudo is not wrong.
  • Apologician
    Apologician about 7 years
    @Rinzwind I used to get errors when testing my environment. I recall seeing gvfs errors. I believe this was fixed by the Ubuntu developers by placing the gvfs files outside of the user's home folder, in /var/run. I may be wrong. Can you give me a method to test where it fails?
  • Rinzwind
    Rinzwind about 7 years
    Continueing: sudo chown -R $(whoami):$(whoami) ~/ is bad advice according to your own reasoning. That command should be edited to include the actual file or dir (ie. sudo chown -R $(whoami):$(whoami) ~./mozilla if it shows mozilla).
  • Apologician
    Apologician about 7 years
    The user broke his system by running sudo when he should have run it as a normal user. There are many occasions where users are braking their system by prefixing sudo on most of their commands. Very common examples are sudo ./confugre and sudo make, sudo thunderbird, sudo google-chrome... Some are taking a short cut and running sudo su to avoid typing sudo. Ubuntu (as far as I know) is about the only distro that has the root login disabled by default. They are trying to discourage normal users from running normal computer task as root...
  • Apologician
    Apologician about 7 years
    ...continued: it appears that it was this that caused the problem. While in this exact thread, Firefox, might be the only application the user was running in the elevated mode, many of the user having this problem are running more than just one application as sudo. The answer was to fix this effect which happens to more than just one folder. I'll spend a lot of time trying to find a way to brake the system using the resolution and make the adjustments. I appreciate your input on this and hope you will help me with examples.