FreeBSD sudo rootとssh-agent

FreeBSD sudo rootとssh-agent

私はFreeBSD 11.3システムでrootアカウントを介してgitサーバーにアクセスしようとしています。 Gitサーバーは保護されており、SSH公開鍵認証を介してのみアクセスを許可します。

FreeBSDボックスにログインすると、ユーザーとしてログインします。次に、ルートにsudoを実行します。 Gitサーバーに接続しようとすると、パスワードの入力を求められます。 sudoを使用せずにユーザーとして残り、gitサーバーに接続しようとすると、SSH公開鍵認証は魅力的に機能します。これはssh -v gitserverの出力です。

OpenSSH_7.5p1, OpenSSL 1.0.2s-freebsd  28 May 2019
debug1: Reading configuration data /root/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to gitserver.xxx.tld [192.168.x.y] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: Fssh_key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_rsa type -1
debug1: Fssh_key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: Fssh_key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa type -1
debug1: Fssh_key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: Fssh_key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa type -1
debug1: Fssh_key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa-cert type -1
debug1: Fssh_key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ed25519 type -1
debug1: Fssh_key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.5 FreeBSD-20170903
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.2p2 Ubuntu-4ubuntu2.8
debug1: match: OpenSSH_7.2p2 Ubuntu-4ubuntu2.8 pat OpenSSH* compat 0x04000000
debug1: Authenticating to gitserver.xxx.tld:22 as '<gituser>'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: [email protected]
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:<here comes a long key expression>
DNS lookup error: data does not exist
debug1: Host 'gitserver.xxx.tld' is known and matches the ECDSA host key.
debug1: Found key in /root/.ssh/known_hosts:1
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_EXT_INFO received
debug1: Fssh_kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Next authentication method: publickey
debug1: Trying private key: /root/.ssh/id_rsa
debug1: Trying private key: /root/.ssh/id_dsa
debug1: Trying private key: /root/.ssh/id_ecdsa
debug1: Trying private key: /root/.ssh/id_ed25519
debug1: Next authentication method: keyboard-interactive
Password:

SSH-agentが私のキーをリモートホストに提供していないようです...

この問題を解決する方法についてのアイデアはありますか?ルートが利用できないキーパスワードを使用できますか(考えただけです)。

オラフ様こんにちは

ベストアンサー1

sudoデフォルトでは、ほとんどすべての環境変数を消去したり、既知の安全値にリセットしてsudoで取得した権限(PATHやLD_LIBRARY_PATHの設定など)を利用したりできないようにします。

env_resetこの機能は、次のオプションをオフにして無効にできます。/etc/sudoers非常に強く推奨しない)またはsudo他の環境変数を保存するように設定できます。たとえば、次のようになります/etc/sudoers

env_keep += "SSH_AGENT_PID SSH_AUTH_SOCK"

詳しく見て知っman sudoersてくださいman sudo


あるいは、このルートアカウントが他の人と共有されていない場合(たとえば、パーソナルコンピュータ)、ルートのキーペアを作成してから、ルートの公開鍵をGitサーバーのユーザーアカウントに追加できます。


PS:私はSSHエージェントを使用する必要はありませんでしたが、viaのようなツールを実行したいときはenv_keep...リモートマシンで実行するために-ingにも使用しました。env_keep += "DISPLAY"gpartedsudossh -Xgparted

おすすめ記事