Linux 以root用户登录后无法打开chrome谷歌浏览器

一.解析

原因

chrome谷歌浏览器默认设置不能以root权限打开,主要是为了软件安全考虑,防止root权限进行破坏操作

解决

通过修改chrome的启动项配置可解决此问题

二、操作步骤

1.使用以下命令打开“/usr/bin/google-chrome”文件

(未安装gedit的可自行用其他的编辑软件打开,vi,vim都可以)

sudo gedit /usr/bin/google-chrome

如下图

#!/bin/sh
if ! [ -x /snap/bin/chromium ]; then
    echo "" >&2
    echo "Command '$0' requires the chromium snap to be installed." >&2
    echo "Please install it with:" >&2
    echo "" >&2
    echo "snap install chromium" >&2
    echo "" >&2
    exit 1
fi

if [ "$(xdg-settings get default-web-browser)" = "chromium-browser.desktop" ]; then
  xdg-settings set default-web-browser chromium_chromium.desktop
fi

# GNOME Shell
OLD="chromium-browser.desktop"
NEW="chromium_chromium.desktop"
FAVS=$(gsettings get org.gnome.shell favorite-apps 2> /dev/null)
if echo "$FAVS" | grep -q "'$OLD'"; then
  NEWFAVS=$(echo $FAVS | sed -e "s#'$OLD'#'$NEW'#")
  gsettings set org.gnome.shell favorite-apps "$NEWFAVS"
fi

# Unity
OLD="application://chromium-browser.desktop"
NEW="application://chromium_chromium.desktop"
FAVS=$(gsettings get com.canonical.Unity.Launcher favorites 2> /dev/null)
if echo "$FAVS" | grep -q "'$OLD'"; then
  NEWFAVS=$(echo $FAVS | sed -e "s#'$OLD'#'$NEW'#")
  gsettings set com.canonical.Unity.Launcher favorites "$NEWFAVS"
fi

# MATE
OLD="/usr/share/applications/chromium-browser.desktop"
NEW="/var/lib/snapd/desktop/applications/chromium_chromium.desktop"
OBJECTS=$(gsettings get org.mate.panel object-id-list 2> /dev/null)
for object in $OBJECTS; do
  object=$(echo $object | cut -d\' -f2)
  launcher=$(gsettings get org.mate.panel.object:/org/mate/panel/objects/$object/ launcher-location)
  if [ "$launcher" = "'$OLD'" ]; then
    gsettings set org.mate.panel.object:/org/mate/panel/objects/$object/ launcher-location "'$NEW'"
  fi
done

# KDE Plasma
if which qdbus > /dev/null; then
  SCRIPT="$(cat <<-EOF
    for (var i = 0; i < panelIds.length; ++i) {
      var panel = panelById(panelIds[i]);
      var widgets = panel.widgets();
      for (var j = 0; j < widgets.length; ++j) {
        var widget = widgets[j];
        if (widget.type == "org.kde.plasma.taskmanager") {
          widget.currentConfigGroup = "General";
          var launchers = widget.readConfig("launchers");
          if (launchers.includes("chromium-browser.desktop")) {
            widget.writeConfig("launchers", launchers.replace(/chromium-browser.desktop/g, "chromium_chromium.desktop"));
          }
        }
      }
    }
EOF
  )"
  qdbus org.kde.plasmashell /PlasmaShell org.kde.PlasmaShell.evaluateScript "$SCRIPT" 2> /dev/null
fi

# TODO: handle other desktop environments

exec /snap/bin/chromium "$@" --user-data-dir --no-sandbox

2.修改最后的配置文件内容,如下所示

exec -a "$0" "$HERE/chrome" "$@"

 修改为

exec -a "$0" "$HERE/chrome" "$@" --user-data-dir --no-sandbox

保存就可以打开了

分享:1.可用命令行输入/usr/bin/google-chrome-stable  --no-sanbox 直接打开谷歌浏览器

           2.桌面快捷方式文件从/usr/share/applications下拷贝chrome文件到桌面

           3.在桌面右键chrome图标,然后在启动中添加参数--no-sanbox,

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值