13

when I want to run google chrome as root, an error message with this title appears:

Google chrome can not be run as root

and the body of message is:

to run as root, you must specify an alternate --user-data-dir for storage of profile information.

can anyone help me?

1
  • 1
    although it's not a good work to run this application as root, I'll explain the method.
    – M0εiπ
    Nov 10 '15 at 16:19
9

To run google chrome as root, follow these steps:

  1. Open google-chrome in your favorite editor (replacing $EDITOR with your favorite):

    $EDITOR $(which google-chrome)
    
  2. Add --user-data-dir at the very end of the file.

    my file looks like this:

    exec -a "$0" "$HERE/chrome"  "$PROFILE_DIRECTORY_FLAG" \   "$@"
    --user-data-dir
    
  3. Save and close the editor.

you’re done. Enjoy it :)


if you want to see video tutorial, you can check my blog post:

How to run google chrome as root in Linux - MoeinFatehi

4
  • 4
    Just to be clear, the correct answer here is “You don't.” Running graphical apps as root really isn't a great idea.
    – HalosGhost
    Dec 26 '14 at 15:52
  • 1
    well I have heard you should not run graphical applications as root and I decided I'd do it just to find out why not. I planned to do it till I found out. This is now 14 years ago. Dec 26 '14 at 15:57
  • 2
    You should read up on the principal of least privilege.
    – HalosGhost
    Dec 26 '14 at 17:54
  • 2
    I ended up having to use --no-sandbox as well. yolo Jun 20 '16 at 18:22
4

Now you cannot run google-chrome as root user on updated versions, To run Google Chrome as standard user (while Logged in as Root)

open terminal and type:

adduser -u chromeuser OR useradd -m chromeuser

To run google chrome use command:

gksu -u chromeuser google-chrome OR sux chromeuser google-chrome

If you don't want to run it from Terminal then add chrome in taskbar and then right-click on it, select properties and add the above command in the command parameter.

1
  • also using an existing user account worked for me : gksu -u gv google-chrome-stable. Though i received some erros in terminal, but it worked. Dec 22 '16 at 9:42
3

For those who may be still googling at Dec 2016 - Google Chrome Version 54.0.2840.90 64bit under XFCE and Debian 8.5:

Case 1: Chrome not starting at all
In my setup just by running in terminal google-chrome-stable i was getting immediately an error in terminal illegal instruction. No frames, no screen blanking , no black windows. Just a rude console error. This error goes away by using the --no-sandbox command line option.

Case 2: Chrome still refuses to open even with --no-sandbox option
That was not my case since --no-sandbox was enough, but if you experience such behavior you could try to disable everything when calling chrome, like:

google-chrome-stable --disable-gpu --disable-extensions --disable-d3d11 --disable-local-storage --disable-notifications --disable-offne-pages --disable-plugin-power-saver --disable-plugins-discovery --disable-sync --disable-translate --disable-webgl --no-experiments --no-sandbox

Then you can step by step enable options till to identify which one breaks.
PS: All CLI flags/args can be found here.

Case 3: Message Please start Google Chrome as a normal user.To run as root you must specify an alternate --user-data-dir for storage of profile information appears.

Solution that worked for me : Go to /opt/google/chrome and open file google-chrome which is actually a bash script.

At the end of the script find the part

if [[ -n "$CHROME_USER_DATA_DIR" ]]; then
  # Note: exec -a below is a bashism.
  exec -a "$0" "$HERE/chrome"  \
    --user-data-dir="$CHROME_USER_DATA_DIR" "$@"
else
  exec -a "$0" "$HERE/chrome"  "$@"
fi

And change the else part like this:

else
  #exec -a "$0" "$HERE/chrome"  "$@"
  exec -a "$0" "$HERE/chrome" "$@" --user-data-dir="$HOME"
fi

Save, and run google-chrome-stable --no-sandbox .
I got up and surfing.

For a more sophisticated solution i personally applied a kind of user check to avoid possible disturbance running chrome as normal user :

else
    if [ "$USER" = "root" ]  || [ "$LOGNAME" = "root" ];then 
        exec -a "$0" "$HERE/chrome" "$@" --user-data-dir="$HOME"
    else
        exec -a "$0" "$HERE/chrome"  "$@"
    fi

Another Workaround:
You can not modify the google-chrome file as indicated above, and you can either follow recomendation of @tzafar for creating a new user or to launch chrome using an existing normal user account : gksu -u user google-chrome-stable (this worked but some error messages received in terminal).

1
2

run the folloing command and open google-chrome it will works

sed -i -e 's@Exec=/usr/bin/google-chrome-stable %U@Exec=/usr/bin/google-chrome-stable %U --no-sandbox@g' /usr/share/applications/google-chrome.desktop 
0

To run google chrome as root, add this parameter "--no-sandbox"

enter image description here

it will works for me.

2
  • What are the actual consequences of doing this?
    – Kusalananda
    Feb 22 '19 at 18:34
  • Are the same as the consequences of using a root account
    – SAID
    Feb 24 '19 at 20:52
0

You can run chrome as root by un-sandboxing it.

I made a simple script that can help enable or disable different browsers in root. The script will present you a menu which will enable or disable a browser based on your selection.

Github repo link

Profile link

Use the profile link incase the repo link wount work.

1
  • Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.
    – slm
    Oct 2 '20 at 23:33
-1

i have try all the solution provided there so by my opinion this one is the best.

sudo chmod -R 777 /home/user_name/.config/google-chrome

just run command you dont need to do anything.

1
  • Hello Abhinav. Could you please explain how this answers the question of running Chrome as root.
    – roaima
    May 24 '19 at 13:59
-2

this is a long shot but try this

sudo chmod -R 777 /home/user_name/.config/google-chrome

dont need to configure sandbox anymore

3
  • How would making all the Chrome config readable by everyone help?
    – Kusalananda
    Apr 14 '19 at 17:50
  • problem is different every time if 'google-chrome --no-sandbox' don't work,usually sudo is required cause it don't have enough permission of the /home/usr_name/.config/google-chrome folder or some other directories. Apr 20 '19 at 15:39
  • Note that root is not restricted by file permissions or file ownerships.
    – Kusalananda
    Apr 20 '19 at 15:54

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