How do I run Google Chrome as root? [closed] - google-chrome

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
Improve this question
I have installed Google Chrome in Ubuntu 10.10. When I try to use in normal user, it is working fine.
Now if I want to use as a root it gives the following error:
Google Chrome does not run as root
Also when I tried the following command in terminal, it opens Google Chrome:
google-chrome --user-data-dir
I need a permanent solution for this. Can anybody give me idea about this?

Run from terminal
# google-chrome --no-sandbox --user-data-dir
or
Open the file opt/google/chrome/google-chrome and replace
exec -a "$0" "$HERE/chrome" "$#"
to
exec -a "$0" "$HERE/chrome" "$#" --user-data-dir --no-sandbox
It's working for chrome version 49 in CentOS 6. Chrome will give warning also.

First solution:
1. switch off Xorg access control: xhost +
2. Now start google chrome as normal user "anonymous" :
sudo -i -u anonymous /opt/google/chrome/chrome
3. When done browsing, re-enable Xorg access control:
xhost -
More info : Howto run google-chrome as root
Second solution:
1. Edit the file /opt/google/chrome/google-chrome
2. find exec -a "$0" "$HERE/chrome" "$#"
or exec -a "$0" "$HERE/chrome" "$PROFILE_DIRECTORY_FLAG" \ "$#"
3. change as
exec -a "$0" "$HERE/chrome" "$#" --user-data-dir ”/root/.config/google-chrome”
Third solution:
Run Google Chrome Browser as Root on Ubuntu Linux systems

Go to /opt/google/chrome.
Open google-chrome.
Append current home for data directory. Replace this:
exec -a "$0" "$HERE/chrome" "$#"
With this:
exec -a "$0" "$HERE/chrome" "$#" --user-data-dir $HOME
For reference visit site this site, “How to run chrome as root user in Ubuntu.”

i followed these steps
Step 1. Open /etc/chromium/default file with editor
Step 2. Replace or add this line
CHROMIUM_FLAGS="--password-store=detect --user-data-dir=/root/chrome-profile/"
Step 3. Save it..
Thats it.... Start the browser...

I tried this with Kali linux, Debian, CentOs 7,And Ubuntu
(Permanent Method)
Edit the file with any text editor (I used Leafpad) Run this code your terminal leafpad/opt/google/chrome/google-chrome
(Normally its end line) find exec -a "$0" "$HERE/chrome" "$#"
or exec -a "$0" "$HERE/chrome" "$PROFILE_DIRECTORY_FLAG" \ "$#"
change as exec -a "$0" "$HERE/chrome" "$#" --no-sandbox --user-data-dir
(Just Simple Method)
Run This command in your terminal
$ google-chrome --no-sandbox --user-data-dir
Or
$ google-chrome-stable --no-sandbox --user-data-dir

Just replace following line
exec -a "$0" "$HERE/chrome" "$#"
with
exec -a "$0" "$HERE/chrome" "$#" --user-data-dir
all things will be right.

It no longer suffices to start Chrome with --user-data-dir=/root/.config/google-chrome. It simply prints Aborted and ends (Chrome 48 on Ubuntu 12.04).
You need actually to run it as a non-root user. This you can do with
gksu -wu chrome-user google-chrome
where chrome-user is some user you've decided should be the one to run Chrome. Your Chrome user profile will be found at ~chrome-user/.config/google-chrome.
BTW, the old hack of changing all occurrences of geteuid to getppid in the chrome binary no longer works.

STEP 1: cd /opt/google/chrome
STEP 2: edit google-chrome file. gedit google-chrome
STEP 3: find this line: exec -a "$0" "$HERE/chrome" "$#".
Mostly this line is in the end of google-chrome file.
Comment it out like this : #exec -a "$0" "$HERE/chrome" "$#"
STEP 4:add a new line at the same place.
exec -a "$0" "$HERE/chrome" "$#" --user-data-dir
STEP 5: save google-chrome file and quit. And then you can use chrome as root user. Enjoy it!

Chrome can run as root (remember to use gksu when doing so) so long as you provide it with a profile directory.
Rather than type in the profile directory every time you want to run it, create a new bash file (I'd name it something like start-chrome.sh)
#/bin/bash
google-chrome --user-data-dir="/root/chrome-profile/"
Rember to call that script with root privelages!
$ gksu /root/start-chrome.sh

Related

How to run strace inside CoreOS toolbox container?

I run coreos and need to run strace on a certain process. However:
strace -s 99 -ffp 8259
strace: attach: ptrace(PTRACE_SEIZE, 8259): Operation not permitted
I opened up the script that spins up the toolbox and found this:
sudo systemd-nspawn \
--directory="${machinepath}" \
--capability=all \
--share-system \
${TOOLBOX_BIND} \
--user="${TOOLBOX_USER}" "$#"
Which is a namespace container. It looks like a permissions issue but I don't know how to give my container permissions to attach strace to process outside of it. My CoreOS version: DISTRIB_RELEASE=1185.5.0
Any help is appreciated
Short answer:
echo 0 > /proc/sys/kernel/yama/ptrace_scope
Longer answer here

"Wrong sources.list entry or malformed file" for Chrome while using `apt-get update`

I am trying to use sudo apt-get update But i am getting error as,
W: Failed to fetch http://dl.google.com/linux/chrome/deb/dists/stable/Release Unable to find expected entry 'main/binary-i386/Packages' in Release file (Wrong sources.list entry or malformed file)
E: Some index files failed to download. They have been ignored, or old ones used instead.
I tired the solution given in https://askubuntu.com/questions/120621/how-to-fix-duplicate-sources-list-entry, but again showing the same error. Suggest me something.
It looks like Google has discontinued support for i386, which is why this error now shows up. It looks like they have not gracefully for how their deb install has configured apt. To fix this run the following.
sudo sed -i -e 's/deb http/deb [arch=amd64] http/' "/etc/apt/sources.list.d/google-chrome.list"
Source: https://www.reddit.com/r/chrome/comments/48oje6/linux_how_to_fix_failed_to_fetch/
Edit: As has been pointed out by others, another command is needed to prevent this fix from reverting. Since this is at the top as the accepted answer I feel it should be part of this answer.
sudo sed -i -e 's/deb http/deb [arch=amd64] http/' "/opt/google/chrome/cron/google-chrome"
Also, this issue may exist if there are two files with name google.list and google-chrome.list in /etc/apt/sources.list.d directory with the similar entry like:
In google.list:
deb http://dl.google.com/linux/chrome/deb/ stable main
In google-chrome.list:
deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main
Then you should remove google.list file or uncomment its entry like below:
#deb http://dl.google.com/linux/chrome/deb/ stable main
That change was reverting overnight for me. Apparently you also need to change /opt/google/chrome/cron/google-chrome
sudo sed -i -e 's/deb http/deb [arch=amd64] http/' "/opt/google/chrome/cron/google-chrome"
Note: this is only for 64-bit
Source: further down that same Reddit thread and http://www.webupd8.org/2016/03/fix-failed-to-fetch-google-chrome_3.html
This doesn't work because there is a default config in /etc/default/google-chrome that contains instructions on repository updating. If you open the google-chrome.list file in /etc/apt/sources.list.d/ you will see that it has the comment:
### THIS FILE IS AUTOMATICALLY CONFIGURED ###
# You may comment out this entry, but any other modifications may be lost.
Like the note says, the changes using the instructions in the previous comments will probably be overwritten the next time you update. To resolve this, do the following:
Open a terminal and run cd /etc/default , then sudo nano google-chrome (Note: you can use whatever editor you wish of course))
In the config file, change the 2nd line: repo_reenable_on_distupgrade="true" so that it is false, as in
repo_reenable_on_distupgrade="false", then save the config file.
Now, you can make the edit to the repo as instructed above. In a terminal window run the commands as shown in the previous comments:
sudo sed -i -e 's/deb http/deb [arch=amd64] http/' "/etc/apt/sources.list.d/google-chrome.list"
sudo sed -i -e 's/deb http/deb [arch=amd64] http/' "/opt/google/chrome/cron/google-chrome"
You changes now won't be overwritten by the config directive.
PS. This works in Linux Mint 17.3 so it will probably work in Ubuntu and any Ubuntu based distro as well.
Go to "Software Sources" section in Ubuntu Settings then click on "other software" tab then uncheck: http://dl.google.com/linux/chrome/deb/stable
Now sudo apt-get update will work.
After updating manager go and undo the changes in software sources.
I solved this problem by following process:
1.Open a new Terminal window and run the following command:
sudo gedit /etc/apt/sources.list.d/google-chrome.list
2.In the text file that opens edit the file so that the line reads:
deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main
N.B: The only addition you need to make is entering the [amd64] architecture after ‘deb’ but preceding the ‘http’. Do not edit or replace any other text in this file.
3.Hit Save. Close the Gedit window and return to the Terminal and refresh your package list by runnin
sudo apt-get update
The ‘failed to fetch’ APT error should no longer appear.
source link
This didn't work for me, until I modified yet another file:
/etc/apt/sources.list.d/additional-repositories.list
and changed:
deb http://dl.google.com/linux/chrome/deb/ stable main
to
deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main

How to execute a script when Chrome is closed?

I want to make a timestamped backup of the bookmarks with rsync everytime Chrome exits. How to trigger a script execution right after Chrome closes?
Edit:
This is the default execution script to start Chrome on Linux Mint with the solution I'm trying to implement:
#!/bin/bash
#
# Copyright (c) 2011 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# Let the wrapped binary know that it has been run through the wrapper.
export CHROME_WRAPPER="`readlink -f "$0"`"
HERE="`dirname "$CHROME_WRAPPER"`"
"/opt/google/chrome/chrome" & pid=$!
wait $pid
if ! pgrep chrome > /dev/null; then
echo "It exited successfully"
fi
# Check if the CPU supports SSE2. If not, try to pop up a dialog to explain the
# problem and exit. Otherwise the browser will just crash with a SIGILL.
# http://crbug.com/348761
grep ^flags /proc/cpuinfo|grep -qs sse2
if [ $? != 0 ]; then
SSE2_DEPRECATION_MSG="This computer can no longer run Google Chrome because \
its hardware is no longer supported."
if which zenity &> /dev/null; then
zenity --warning --text="$SSE2_DEPRECATION_MSG"
elif which gmessage &> /dev/null; then
gmessage "$SSE2_DEPRECATION_MSG"
elif which xmessage &> /dev/null; then
xmessage "$SSE2_DEPRECATION_MSG"
else
echo "$SSE2_DEPRECATION_MSG" 1>&2
fi
exit 1
fi
# We include some xdg utilities next to the binary, and we want to prefer them
# over the system versions when we know the system versions are very old. We
# detect whether the system xdg utilities are sufficiently new to be likely to
# work for us by looking for xdg-settings. If we find it, we leave $PATH alone,
# so that the system xdg utilities (including any distro patches) will be used.
if ! which xdg-settings &> /dev/null; then
# Old xdg utilities. Prepend $HERE to $PATH to use ours instead.
export PATH="$HERE:$PATH"
else
# Use system xdg utilities. But first create mimeapps.list if it doesn't
# exist; some systems have bugs in xdg-mime that make it fail without it.
xdg_app_dir="${XDG_DATA_HOME:-$HOME/.local/share/applications}"
mkdir -p "$xdg_app_dir"
[ -f "$xdg_app_dir/mimeapps.list" ] || touch "$xdg_app_dir/mimeapps.list"
fi
# Always use our versions of ffmpeg libs.
# This also makes RPMs find the compatibly-named library symlinks.
if [[ -n "$LD_LIBRARY_PATH" ]]; then
LD_LIBRARY_PATH="$HERE:$HERE/lib:$LD_LIBRARY_PATH"
else
LD_LIBRARY_PATH="$HERE:$HERE/lib"
fi
export LD_LIBRARY_PATH
export CHROME_VERSION_EXTRA="stable"
# We don't want bug-buddy intercepting our crashes. http://crbug.com/24120
export GNOME_DISABLE_CRASH_DIALOG=SET_BY_GOOGLE_CHROME
# Automagically migrate user data directory.
# TODO(phajdan.jr): Remove along with migration code in the browser for M33.
if [[ -n "" ]]; then
if [[ ! -d "" ]]; then
"$HERE/chrome" "--migrate-data-dir-for-sxs=" \
--enable-logging=stderr --log-level=0
fi
fi
# Sanitize std{in,out,err} because they'll be shared with untrusted child
# processes (http://crbug.com/376567).
exec < /dev/null
exec > >(exec cat)
exec 2> >(exec cat >&2)
# Make sure that the profile directory specified in the environment, if any,
# overrides the default.
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
What OS are you using? In OS X, this shell script will start Chrome and then do stuff when Chrome quits - it should be easy to adapt it for your needs in any Unix-like OS.
#! /usr/bin/env sh
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" & pid=$!
wait $pid
if ! pgrep Chrome > /dev/null; then # no instances of Chrome are running
# do stuff
fi
(based on this answer)
Edit: And this works for me in Ubuntu:
#! /usr/bin/env sh
/opt/google/chrome/chrome & pid=$!
wait $pid
if ! pgrep chrome > /dev/null; then
# do stuff
fi
Due to the way Google Chrome uses processes, monitoring (PID) the process of a specific Google Chrome window (or instance) of it is usually a headache or (almost) impossible.
But, there is a workaround way that makes this possible. Just use the --user-data-dir parameter pointing to the /tmp folder (--user-data-dir=/tmp).
Below, to illustrate, I've created a bash script that starts the http Web service Gitea, opens it in a Google Chrome, and then terminates it when the Google Chrome window is closed.
#!/bin/bash
gitea & GITEA_PID=$!
sleep 3
google-chrome-stable --user-data-dir=/tmp --app=http://0.0.0.0:3000/ & CHROME_PID=$!
wait $CHROME_PID
kill -9 $GITEA_PID
Basically I'm using your same idea. Just adapt. 🥰
[Ref(s).: https://stackoverflow.com/a/75013043/3223785 ,
https://stackoverflow.com/a/35294908/3223785 ,
https://www.ghacks.net/2013/10/06/list-useful-google-chrome-command-line-switches/ ,
https://www.reddit.com/r/firefox/comments/w61dwi/how_do_i_start_firefox_in_a_single_window_with/?utm_source=share&utm_medium=web2x&context=3 , ]

how to execute init scripts from the command line using ssh

ssh -t user#server1 "ls -al /root/test/"
Above mentioned code works fine and displays all the contents of the test directory folder but this code fails
ssh -t user#server1 "/etc/init.d/mysql start"
It does not start the mysql server, I have login in to server and use the same command to start the mysql server
Can any one explain this behaviour ? what I am doing wrong bit puzzled :(
Do something like this:
ssh user#hostname "/etc/init.d/mysql start < /dev/null > /tmp/log 2>&1 &"
ssh needs to use stdin and stdout to interact. This will allow it to do that and redirect the output to somewhere useful.
I'm not sure about roots of this behaviour, probably because ssh allocates pseudo-terminal. However you can use workaround with sudo:
ssh -t user#server1 "sudo service mysql start"

Using openshift rhc tail command

How do you tail openshift log files? I issued the following command:
rhc tail myapp
It seems to show first error line and then stops, but doesn't exit. If I press ctrl+C it asks whether to stop batch or not. How can I display last few errors and may be browse page by page? Is there page down/ page up shortcuts?
The 'rhc tail' command reads the last few lines of each of your log files and continues to feed subsequent log messages to your console. To view the entire log file, please review:
https://www.openshift.com/faq/how-to-troubleshoot-application-issues-using-logs
you can see by running:
rhc tail -a yourappname -l youremail -p yourpassword
Adding -a option fix this issue for me.
rhc tail -a {app_name}
Openshift place logs in different files, so if you want get logs of a specific file then you can add -f file/address/and/name
Example :
rhc tail -f app-root/logs/nodejs.log -a myAppName
also you can ask for specific number of lines by adding -o "-n 40" in command. Above command will get last 40 lines.
Example :
rhc tail -f app-root/logs/nodejs.log -o "-n 40" -a myAppName
You can also download them:
$ scp SHA#APP-DOMAIN.rhcloud.com:/var/lib/openshift/SHA/app-root/\
logs/APP.log "~/upstream.jbossas.log"
Feasible also in windows directly in git bash.