创建一个破坏现有权限的新用户

tec*_*ous 7 users ssh chmod git

我有一台运行 Ubuntu 的机器,~/.ssh/config其中包含具有以下权限的 SSH 配置文件(创建新文件时的默认设置)

-rw-rw-r--  1 dev dev   75 Oct 26 20:13 config
Run Code Online (Sandbox Code Playgroud)

创建与现有用户 (dev) 具有相同主要组 (dev) 的新用户 (test) 后,以 dev 身份登录时,我无法再执行 git clone。

dev@vm:~$ git clone ...
Cloning into ...
Bad owner or permissions on /home/dev/.ssh/config
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
Run Code Online (Sandbox Code Playgroud)

谷歌搜索似乎表明我可以通过运行来解决 ssh 问题chmod 600 ~/.ssh/config,但为什么这会成为一个问题?我怎样才能系统地解决这个问题,因为我认为这也会影响其他文件?

谢谢!

ste*_*ver 17

在 openssh-7.6p1 源代码文件中,readconf.c我们可以看到权限检查委托给了一个函数secure_permissions

if (flags & SSHCONF_CHECKPERM) {
        struct stat sb;

        if (fstat(fileno(f), &sb) == -1)
                fatal("fstat %s: %s", filename, strerror(errno));
        if (!secure_permissions(&sb, getuid()))
                fatal("Bad owner or permissions on %s", filename);
}
Run Code Online (Sandbox Code Playgroud)

这个函数在里面misc.c,我们可以看到如果文件是组可写的,它确实明确地强制每个组一个成员:

int
secure_permissions(struct stat *st, uid_t uid)
{
        if (!platform_sys_dir_uid(st->st_uid) && st->st_uid != uid)
                return 0;
        if ((st->st_mode & 002) != 0)
                return 0;
        if ((st->st_mode & 020) != 0) {
                /* If the file is group-writable, the group in question must
                 * have exactly one member, namely the file's owner.
                 * (Zero-member groups are typically used by setgid
                 * binaries, and are unlikely to be suitable.)
                 */
                struct passwd *pw;
                struct group *gr;
                int members = 0;

                gr = getgrgid(st->st_gid);
                if (!gr)
                        return 0;

                /* Check primary group memberships. */
                while ((pw = getpwent()) != NULL) {
                        if (pw->pw_gid == gr->gr_gid) {
                                ++members;
                                if (pw->pw_uid != uid)
                                        return 0;
                        }
                }
                endpwent();

                pw = getpwuid(st->st_uid);
                if (!pw)
                        return 0;

                /* Check supplementary group memberships. */
                if (gr->gr_mem[0]) {
                        ++members;
                        if (strcmp(pw->pw_name, gr->gr_mem[0]) ||
                            gr->gr_mem[1])
                                return 0;
                }

                if (!members)
                        return 0;
        }
        return 1;
}
Run Code Online (Sandbox Code Playgroud)


bla*_*imi 5

这与ssh有关。ssh 要求文件~/.ssh/config只能由它影响的用户读取,其他人不能读取。大多数系统(rw-rw-r-- 或 rw-r--r--)默认文件权限为 664 或 644。您可以通过设置 umask 来控制它。

git clone 正在使用 ssh 克隆存储库,即使克隆是从 http(s) 完成的,它也可能在 init 上使用了一些 ssh-stuff。

链接:

  • 必须只能由所有者写;其他人可以读取配置和公钥文件,包括known_hosts 和authorized_keys;PRIVATEKEY 文件必须只能由所有者读取(即使是加密的,这独立地应该提供机密性)。我不知道 die.net 在哪里找到了 _2013_ (!) 手册页,但请在 https://man.openbsd.org/ssh.1#FILES 和 https://man.openbsd.org 查看当前维护的版本/ssh_config.5#FILES (4认同)