How to run google chrome as root in linux

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


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.


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).