删除一些不需要的组

删除一些不需要的组

我从 Ubuntu 17.04 升级到了 17.10。我遇到了两个问题:

1. 升级时产生了以下错误日志:

  • 无法安装“network-manager-openvpu”子进程安装后安装脚本返回错误退出状态 1
  • 无法安装“geoclue-2.0”子进程安装后安装脚本返回错误退出状态 1
  • 升级已中止。您的系统可能处于不可用状态。现在将运行恢复 (dpkg --config -a)
  • 升级已完成,但升级过程中出现错误

2. 我无法从购物袋图标/软件中心下载任何东西:

  • 无法安装 [在此处放置任何软件] 安装包时出错:子进程安装后安装脚本返回错误退出状态 1

附件

我做到了

sudo apt autoremove

然后这个

sudo apt install --fix-missing
Reading package lists... Done
Building dependency tree       
Reading state information... Done
0 to upgrade, 0 to newly install, 0 to remove and 0 not to upgrade.
4 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Setting up gdm3 (3.26.1-3ubuntu3) ...
addgroup: No GID is available in the range 100-999 (FIRST_SYS_GID - LAST_SYS_GID).
addgroup: The group `gdm' was not created.
dpkg: error processing package gdm3 (--configure):
 subprocess installed post-installation script returned error exit status 1
Setting up geoclue-2.0 (2.4.7-1ubuntu1) ...
addgroup: No GID is available in the range 100-999 (FIRST_SYS_GID - LAST_SYS_GID).
addgroup: The group `geoclue' was not created.
dpkg: error processing package geoclue-2.0 (--configure):
 subprocess installed post-installation script returned error exit status 1
dpkg: dependency problems prevent configuration of empathy:
 empathy depends on geoclue-2.0 (>= 2.0); however:
  Package geoclue-2.0 is not configured yet.

dpkg: error processing package empathy (--configure):
 dependency problems - leaving unconfigured
No apport report written because the error message indicates it's a follow-up error from a previous failure.
                            dpkg: dependency problems prevent configuration of ubuntu-desktop:
 ubuntu-desktop depends on gdm3; however:
  Package gdm3 is not configured yet.

dpkg: error processing package ubuntu-desktop (--configure):
 dependency problems - leaving unconfigured
No apport report written because MaxReports has already been reached
                                                                    Errors were encountered while processing:
 gdm3
 geoclue-2.0
 empathy
 ubuntu-desktop
E: Sub-process /usr/bin/dpkg returned an error code (1)

答案1

删除一些不需要的组

步骤 1 - 完整系统备份

此答案中的命令可能会对您的系统造成严重破坏。使用您喜欢的方法进行完整系统备份。验证/测试此备份。保护您的备份,以免以下步骤损坏它们。
有关备份的更多信息,请参阅Ubuntu 社区维基-备份你的系统我会推荐克隆兹拉一次性完整操作系统和用户数据备份。但对于持续备份,我使用Borg 备份

第 2 步 - 选择要删除的群组和用户

运行getent group | egrep \:[1-9][0-9][0-9]\:将列出 100-999 范围内的组。从此列表中记下至少 10 个与来宾帐户相关的不需要的组。它们不应有任何用户列为组的一部分,也不应是当前安装的程序。以下代码块显示第四个字段包含该组中的用户。在这几个中,只有 sambashare 有用户。只有“guest-”组有问题。

saned:x:122:
uuidd:x:123:
sambashare:x:124:jon
ssh:x:125:
geoclue:x:126:
guest-262uVu:x:127:
guest-qAD7pX:x:128:
guest-H1HJgy:x:129:
guest-fbfgab:x:130:
guest-LdeNZx:x:131:
guest-jIHtqC:x:132:
guest-w7GINW:x:133:

步骤 3 - 删除不需要的组

在以下命令中,用<NEWGID>一个组替换以保存任何残留文件。您可以使用现有组或新组。还可以用<OLDGID>要删除的组替换。对要删除的每个组运行一次​​命令。如果您不想要旧组中的任何文件,请运行可能非常有害的命令find / -group <OLDGID> -exec rm {} \;。如果您不关心谁最终拥有已删除的组文件,您可以运行delgroup --only-if-empty <OLDGID>

find / -group <OLDGID> -exec rm {} \;
find / -group <OLDGID> -exec chgrp -h <NEWGID> {} \;
delgroup --only-if-empty <OLDGID>
# example using random groups
find / -group 200 -exec chgrp -h 2000 {} \;
delgroup --only-if-empty 200

步骤 4 - 清理

运行sudo dpkg --configure -a以完成配置解压后的包。

涵盖步骤 2-4 的 bash 脚本。打开文本编辑器,复制并粘贴以下代码块。将文件另存为guest.sh。在终端中导航到guest.sh保存的位置。运行chmod +x guest.sh,使文件可执行。然后运行./guest.sh

#!/bin/bash
TEMP=$(mktemp --tmpdir)

getent group | grep guest- | cut --delimiter=: -f 3 > "$TEMP"

NGID=$(head -n1 "$TEMP")
GIDS=$(grep -v "$NGID" "$TEMP" | tr '\n' ' ')

for i in $GIDS
    do
        find / -group "$i" -exec chgrp -h "$NGID" {} \;
        delgroup --only-if-empty "$i"
    done
rm "$TEMP"
sudo dpkg --configure -a

相关内容