質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
CentOS

CentOSは、主にRed Hat Enterprise Linux(RHEL)をベースにした、フリーのソフトウェアオペレーティングシステムです。

SSH

SSH(Secure Shell)は、セキュアチャネルを通してデータを交換するためのネットワークプロトコルです。リモートサーバーへのコマンド実行やファイル転送を行う時に一般的に使用されます。

Linux

Linuxは、Unixをベースにして開発されたオペレーティングシステムです。日本では「リナックス」と呼ばれています。 主にWebサーバやDNSサーバ、イントラネットなどのサーバ用OSとして利用されています。 上位500のスーパーコンピュータの90%以上はLinuxを使用しています。 携帯端末用のプラットフォームAndroidは、Linuxカーネル上に構築されています。

Q&A

解決済

1回答

4748閲覧

SFTPのパスワード認証の無効化について

a-chan0000

総合スコア15

CentOS

CentOSは、主にRed Hat Enterprise Linux(RHEL)をベースにした、フリーのソフトウェアオペレーティングシステムです。

SSH

SSH(Secure Shell)は、セキュアチャネルを通してデータを交換するためのネットワークプロトコルです。リモートサーバーへのコマンド実行やファイル転送を行う時に一般的に使用されます。

Linux

Linuxは、Unixをベースにして開発されたオペレーティングシステムです。日本では「リナックス」と呼ばれています。 主にWebサーバやDNSサーバ、イントラネットなどのサーバ用OSとして利用されています。 上位500のスーパーコンピュータの90%以上はLinuxを使用しています。 携帯端末用のプラットフォームAndroidは、Linuxカーネル上に構築されています。

0グッド

0クリップ

投稿2019/05/07 06:44

編集2019/05/16 07:59

SSHとSFTPに詳しい方がいらっしゃいましたら教えていただけると助かります。

コンフィグファイル全体でパスワード認証を無効にしているのにも関わらず、
c-userでSFTPではパスワード認証をパスしてログインできてしまいます。
SFTPのパスワード認証を無効にしたいのですがどのようにすればよいのかご助力をお願いしたいです。

コンフィグファイルの関係のありそうなところのみ抜粋してみます。
SSHからのログイン認証だと問題なく設定が反映されており、
公開鍵認証でしかログインできないことを確認しています。

#RSAAuthentication yes PubkeyAuthentication yes # The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2 # but this is overridden so installations will only check .ssh/authorized_keys AuthorizedKeysFile .ssh/authorized_keys # To disable tunneled clear text passwords, change to no here! PasswordAuthentication no PermitEmptyPasswords no # Accept locale-related environment variables AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE AcceptEnv XMODIFIERS # override default of no subsystems Subsystem sftp /usr/libexec/openssh/sftp-server Protocol 2 PermitRootLogin no AllowUsers a-user b-user c-user Match User a-user ChrootDirectory /var/www/public_html PasswordAuthentication no ForceCommand internal-sftp Match User b-user ChrootDirectory /var/www/stage_html PasswordAuthentication no ForceCommand internal-sftp Match User c-user PasswordAuthentication no AuthorizedKeysFile .ssh/authorized_keys

この設定で、いずれのユーザは公開鍵認証でパスしてログインできます。

a-user、b-userはSFTP専用のユーザです。
c-userのみSSHでもSFTPでも公開鍵認証でログインできるようにしたいです。
ただし、パスワード認証は無効にしたいです。

以上、よろしくお願いいたします。

デバッグログの追加

皆さん、お忙しいところありがとうございます。
以下、ログを追記します。

sftp -v c-user@hostname

OpenSSH_for_Windows_7.6p1, LibreSSL 2.6.4 debug1: Connecting to 192.168.100.128 [192.168.100.128] port 22. debug1: Connection established. debug1: identity file C:\Users\TestTaro/.ssh/id_rsa type 0 debug1: key_load_public: No such file or directory debug1: identity file C:\Users\TestTaro/.ssh/id_rsa-cert type -1 debug1: key_load_public: No such file or directory debug1: identity file C:\Users\TestTaro/.ssh/id_dsa type -1 debug1: key_load_public: No such file or directory debug1: identity file C:\Users\TestTaro/.ssh/id_dsa-cert type -1 debug1: key_load_public: No such file or directory debug1: identity file C:\Users\TestTaro/.ssh/id_ecdsa type -1 debug1: key_load_public: No such file or directory debug1: identity file C:\Users\TestTaro/.ssh/id_ecdsa-cert type -1 debug1: key_load_public: No such file or directory debug1: identity file C:\Users\TestTaro/.ssh/id_ed25519 type -1 debug1: key_load_public: No such file or directory debug1: identity file C:\Users\TestTaro/.ssh/id_ed25519-cert type -1 debug1: Local version string SSH-2.0-OpenSSH_for_Windows_7.6 debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4 debug1: match: OpenSSH_7.4 pat OpenSSH* compat 0x04000000 debug1: Authenticating to 192.168.100.128:22 as 'c-user' debug1: SSH2_MSG_KEXINIT sent debug1: SSH2_MSG_KEXINIT received debug1: kex: algorithm: curve25519-sha256 debug1: kex: host key algorithm: rsa-sha2-512 debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none debug1: expecting SSH2_MSG_KEX_ECDH_REPLY debug1: Server host key: ssh-rsa SHA256:OoA7eSVUMLPCOHyRqEdghTPwIMY4ALeBkss3UL46yeH debug1: Host '[192.168.100.128]:22' is known and matches the RSA host key. debug1: Found key in C:\Users\TestTaro/.ssh/known_hosts:6 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: pubkey_prepare: ssh_get_authentication_socket: No such file or directory debug1: SSH2_MSG_EXT_INFO received debug1: 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,keyboard-interactive debug1: Next authentication method: publickey debug1: Offering public key: RSA SHA256:EWO02bWTW3fDAwCyHYdcsWtYKsXtlOLVT6wISNM57tl C:\Users\TestTaro/.ssh/id_rsa debug1: Authentications that can continue: publickey,keyboard-interactive debug1: Trying private key: C:\Users\TestTaro/.ssh/id_dsa debug1: Trying private key: C:\Users\TestTaro/.ssh/id_ecdsa debug1: Trying private key: C:\Users\TestTaro/.ssh/id_ed25519 debug1: Next authentication method: keyboard-interactive debug1: read_passphrase: can't open /dev/tty: No such file or directory Password: debug1: Authentication succeeded (keyboard-interactive). Authenticated to 192.168.100.128 ([192.168.100.128]:22). debug1: channel 0: new [client-session] debug1: Requesting no-more-sessions@openssh.com debug1: Entering interactive session. debug1: pledge: network debug1: client_input_global_request: rtype hostkeys-00@openssh.com want_reply 0 debug1: Sending subsystem: sftp Connected to c-user@192.168.100.128.

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

CHERRY

2019/05/07 07:01

パスワード認証でログインしているというのは、どのようにかくにんされたのでしょうか? コマンドラインから ` sftp -vv c-user@hostname ` などのように実行して、画面に表示されるデバッグログを確認した場合、パスワード認証の処理になっているのでしょうか?
a-chan0000

2019/05/08 01:08

コメントありがとうございます。 そうです。CUI(cmd)で”sftp -vv c-user@hostname ”で確認しています。その際にオプション-iで秘密鍵ファイルを指定しなくてもログイン認証が成功します。
CHERRY

2019/05/08 03:11

うーん。 同じ様な設定( Match User )を入れてみましたが、こちらでは、下記のようなメッセージがでて sftp でもパスワードログインできませんね。 $ sftp user@host.example.com Permission denied (publickey,gssapi-keyex,gssapi-with-mic). Connection closed sshd_config で、LogLevel を DEBUG2 等にしてみましたが、 `debug1: user user1 matched 'User user1' at line xxx ` のように出ているので、Match User user1 の設定は、適用されているようです。
a-chan0000

2019/05/08 05:10

検証までしていただきありがとうございます!!普通はそのように動きますよね・・・;_; ちなみに/etc/sshd_configの設定変更した後にsshdの再起動をするだけで、 sftpサーバにも反映されるものとの認識で問題ないでしょうか。 CentOsなので、 # systemctl restart sshd で再起動しているのですが、実際はsftpサービスがほかにあって、未反映だからとか・・・脳裏に過ぎっています
yukky1201

2019/05/09 14:43

c-userがパスワード認証でログインできてしまっているのでしょうか。 「オプション-iで秘密鍵ファイルを指定しなくてもログイン認証が成功します。」というのが、指定して稲野のでデフォルト保存場所の鍵(~/.ssh/id_rsaなど)を参照して鍵認証でログインできてたりしませんか。 ログイン試行時のサーバ側のログ(/var/log/secure)も確認すると良いと思います。
doda

2019/05/14 02:23

sftp -v c-user@hostname の結果を出す事が出来ますか? > ちなみに/etc/sshd_configの設定変更した後にsshdの再起動をするだけで、 > sftpサーバにも反映されるものとの認識で問題ないでしょうか。 はい、それで問題無いです。 sftpコマンドは内部でsshコマンドを実行して接続するので、基本的には認証まではsshコマンドで接続した時と同じ動作になります。違いが出てくるのは認証の後になります。
a-chan0000

2019/05/16 08:03 編集

>yukky1201様 デフォルト保存場所の鍵(~/.ssh/id_rsaなど)もログでは参照しているようですが、次の認証処理に続いているのでデフォルト保存場所の鍵の影響ではなさそうです。 > doda様 ありがとうございます!!! sftp -v c-user@hostname の結果を、質問本文下部に追記しました。 keyboard-interactiveモードのせいで、パスワード認証のようになっているような感じですかね・・・
guest

回答1

0

ベストアンサー

ログを見ると、keyboard-interactive認証が使われていますね。
この認証方式はチャレンジ-レスポンス方式の認証などで使われますが、
設定によってはパスワード認証のようにも使えます。

この認証方式をユーザ毎に使えなくする事はできないので、止めるならばシステム全体で止める事になります。
それで問題なければ、以下の設定を sshd_config に追加してサービスを再起動してください。

ChallengeResponseAuthentication no

投稿2019/05/16 09:27

doda

総合スコア947

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

a-chan0000

2019/05/17 03:03

パスワードが聞かれなり、公開鍵認証のみとなりました! 大変助かりました!!! ありがとうございました><
CHERRY

2019/05/17 03:47

セットアップ時に no にしている項目だな... うちの環境で再現しないわけだ。
a-chan0000

2019/05/20 07:33

この度はご助力いただきまして、本当にありがとうございました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問