SSHサーバーがルートコンテキストで実行されている場合、SFTPはどのように特定のユーザーファイルにのみアクセスできますか?

SSHサーバーがルートコンテキストで実行されている場合、SFTPはどのように特定のユーザーファイルにのみアクセスできますか?

この質問は非常に具体的に聞こえるかもしれませんが、これは私が直接SSHサーバーを作成していて(会社では特定のものが必要です)、SFTPがあるからです。ただし、サーバーはrootとして実行されるため、SFTPサービスを使用しているすべてのユーザーにアクセスできます。コンテンツ。

Bashセッションの場合、これを実行するので問題はありません。

sudo -H -u $USER bash

しかし、私はユーザー認証なしでSFTPを使用しています。

デフォルトのSSHサーバーもrootとして実行されていると思うので、SSHがこれをどのように処理するのか疑問に思います。ただし、おそらくSSHで使用されているSFTPサービスが認証を許可する可能性があります。

私はユーザーがログインするたびに別のサーバーを作成できると思いましたが、このようなSFTPに固有のものです。

sudo -u $USER bash -c "my_server -sftponly

これにより、SFTPサーバーはそのユーザーのファイルにのみアクセスできますが、これは重複していると思います。

図書館

golang.org/x/crypto/ssh
github.com/pkg/sftp

ベストアンサー1

他のユーザーにroot権限を譲渡するツールは、単にこの目的のために提供されたシステムコールを使用するようです。

$ man setuid
SETUID(2)                 FreeBSD System Calls Manual                SETUID(2)

NAME
     setuid, seteuid, setgid, setegid - set user and group ID

LIBRARY
     Standard C Library (libc, -lc)

SYNOPSIS
     #include <unistd.h>

     int
     setuid(uid_t uid);

     int
     seteuid(uid_t euid);

     int
     setgid(gid_t gid);

     int
     setegid(gid_t egid);

DESCRIPTION
     The setuid() system call sets the real and effective user IDs and the
     saved set-user-ID of the current process to the specified value.  The
     setuid() system call is permitted if the specified ID is equal to the
     real user ID or the effective user ID of the process, or if the effective
     user ID is that of the super user.

     The setgid() system call sets the real and effective group IDs and the
     saved set-group-ID of the current process to the specified value.  The
     setgid() system call is permitted if the specified ID is equal to the
     real group ID or the effective group ID of the process, or if the
     effective user ID is that of the super user.

     The seteuid() system call (setegid()) sets the effective user ID (group
     ID) of the current process.  The effective user ID may be set to the
     value of the real user ID or the saved set-user-ID (see intro(2) and
     execve(2)); in this way, the effective user ID of a set-user-ID
     executable may be toggled by switching to the real user ID, then re-
     enabled by reverting to the set-user-ID value.  Similarly, the effective
     group ID may be set to the value of the real group ID or the saved set-
     group-ID.

RETURN VALUES
     Upon successful completion, the value 0 is returned; otherwise the
     value -1 is returned and the global variable errno is set to indicate the
     error.

ERRORS
     The system calls will fail if:

     [EPERM]            The user is not the super user and the ID specified is
                        not the real, effective ID, or saved ID.

おすすめ記事