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

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

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

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

Q&A

解決済

1回答

18150閲覧

SFTP ログインで失敗する

tequilla917

総合スコア4

Linux

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

0グッド

1クリップ

投稿2020/08/27 02:52

編集2020/08/28 07:16

実現したいこと

sftpuserユーザでSFTPにログインしファイルをgetしたいです。
しかしログインエラーとなっており、権限変更等も行っているのですが出来ない状況です。
どの部分が誤っているのかをご教授頂きたいです。
なお、パスワード認証方式でログインを行い、鍵認証は付けない方針で設定したいです。

試したこと

権限の変更等は行なっております。
/home/sftpuser/.ssh 700

補足情報

<サーバ情報>
172.168.0.9 サーバ1 sftpuser
172.168.0.7 サーバ2 sftpuser
→サーバ1のsftpuserユーザでサーバ2にある資産をgetしたい
→サーバ2にsftpuserはいらないのですが念の為作成している状況

<sshd.config設定>(パーミッションは600でサーバ1、2共通の記載)
PermitRootLogin Yes
PasswordAuthentication Yes
※以下は追記分
Match User sftpuser
ChrootDirectory /home/sftpuser/
ForceCommand internal-sftp
PasswordAuthentication Yes

<実施コマンドと出力結果(エラーも含む)>

sudo su - sftpuser
whoami

sftpuser

sftp-oPort="22" sftpuser@172.168.0.7

sftpuser@172.168.0.7's password:(172.168.0.7ログイン時のパスワード入力)
Permission denied,please try again
sftpuser@172.168.0.7's password:
Permission denied,please try again
sftpuser@172.168.0.7's password:
Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
Couldn't read packet:Connect reset by peer

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

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

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

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

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

yukky1201

2020/08/27 06:41

「サーバ1 から サーバ2 へsftp接続する」で合ってますか? 上記前提で、「サーバ2 に sftpuser というユーザ」は作成していますか? また、鍵認証の設定(なんていう鍵ファイル を どちらのサーバ の なんていうファイルに登録したか)を提示してください
tequilla917

2020/08/28 06:57

>>>「サーバ1 から サーバ2 へsftp接続する」で合ってますか? →認識合ってます。 >>>「サーバ2 に sftpuser というユーザ」は作成していますか? →両サーバにsftpuserは作成済みです。 >>>鍵認証の設定 →申し訳ないです。実現したいことが少し違っていましたので、質問自体を少し訂正させて頂きます。
bsdfan

2020/09/02 08:12

サーバ2(ログイン先)のsshdのログを確認してみてください。エラーの原因がわかるかもしれません。 /var/log/secure か journalctl -u sshd とりあえず、まずはsftpではなくssh(シェル)で接続できることを目指したほうがよいのではないでしょうか。以下の設定は削除して試行錯誤し、うまくいってから追加したらいいと思います。 Match User sftpuser ChrootDirectory /home/sftpuser/ ForceCommand internal-sftp
tequilla917

2020/09/02 08:19

Match User sftpuser ChrootDirectory /home/sftpuser/ ForceCommand internal-sftp の記述を削除したら上手く行きました。 ssh、sftpともに問題なさそうです。
guest

回答1

0

ベストアンサー

<sshd.config設定>とありますが、ファイル名でしょうか。

私の環境(FreeBSD)では/etc/ssh/sshd_
configですし、
Virtualbox上で飼っているCentOS7も/etc/ssh/sshd_configでした。

あなたの使用しているOSは何でしょう?

投稿2020/08/29 12:26

編集2020/08/29 12:29
hana_yama_san

総合スコア923

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

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

tequilla917

2020/08/29 14:46

申し訳ないです。こちらの記載ミスです。指摘にある通り、「sshd_config」です。 ちなみに使用しているOSは「RHEL7」です。
hana_yama_san

2020/08/30 09:10

承知しました。 sftp -v -o Port="22" sftpuser@172.168.0.7 ↑でデバック出力を見てください。 また、 grep sshd /var/log/secure も、実行してみましょう。
tequilla917

2020/08/31 00:30

上記コマンド実行してみました。 grepは出力されないようです。 id_dsaを見に行っているようで、パスワード認証になっていないような気がしました。 #sftp -v -oPort="22" sftpuser@172.168.0.7 OpenSSH_7.4p1, OpenSSL 1.0.2k-fips 26 Jan 2017 debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 58: Applying options for * debug1: Connecting to 172.168.0.7 [172.168.0.7] port 22. debug1: Connection established. debug1: identity file /home/sftpuser/.ssh/id_rsa type 1 debug1: key_load_public: No such file or directory debug1: identity file /home/sftpuser/.ssh/id_rsa-cert type -1 debug1: key_load_public: No such file or directory debug1: identity file /home/sftpuser/.ssh/id_dsa type -1 debug1: key_load_public: No such file or directory debug1: identity file /home/sftpuser/.ssh/id_dsa-cert type -1 debug1: key_load_public: No such file or directory debug1: identity file /home/sftpuser/.ssh/id_ecdsa type -1 debug1: key_load_public: No such file or directory debug1: identity file /home/sftpuser/.ssh/id_ecdsa-cert type -1 debug1: key_load_public: No such file or directory debug1: identity file /home/sftpuser/.ssh/id_ed25519 type -1 debug1: key_load_public: No such file or directory debug1: identity file /home/sftpuser/.ssh/id_ed25519-cert type -1 debug1: Enabling compatibility mode for protocol 2.0 debug1: Local version string SSH-2.0-OpenSSH_7.4 debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4 debug1: match: OpenSSH_7.4 pat OpenSSH* compat 0x04000000 debug1: Authenticating to 172.168.0.7:22 as 'sftpuser' debug1: SSH2_MSG_KEXINIT sent debug1: SSH2_MSG_KEXINIT received debug1: kex: algorithm: curve25519-sha256 debug1: kex: host key algorithm: ecdsa-sha2-nistp256 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: kex: curve25519-sha256 need=64 dh_need=64 debug1: kex: curve25519-sha256 need=64 dh_need=64 debug1: expecting SSH2_MSG_KEX_ECDH_REPLY debug1: Server host key: ecdsa-sha2-nistp256 SHA256:DsxCuiE0PhLC2x3RpyCwvapUGt72f2wOYO1FZPo+98E debug1: Host '172.168.0.7' is known and matches the ECDSA host key. debug1: Found key in /home/sftpuser/.ssh/known_hosts:2 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: 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,gssapi-keyex,gssapi-with-mic,password debug1: Next authentication method: gssapi-keyex debug1: No valid Key exchange context debug1: Next authentication method: gssapi-with-mic debug1: Unspecified GSS failure. Minor code may provide more information No Kerberos credentials available (default cache: KEYRING:persistent:1001) debug1: Unspecified GSS failure. Minor code may provide more information No Kerberos credentials available (default cache: KEYRING:persistent:1001) debug1: Next authentication method: publickey debug1: Offering RSA public key: /home/sftpuser/.ssh/id_rsa debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password debug1: Trying private key: /home/sftpuser/.ssh/id_dsa debug1: Trying private key: /home/sftpuser/.ssh/id_ecdsa debug1: Trying private key: /home/sftpuser/.ssh/id_ed25519 debug1: Next authentication method: password sftpuser@172.168.0.7's password: debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password Permission denied, please try again. sftpuser@172.168.0.7's password: debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password Permission denied, please try again. sftpuser@172.168.0.7's password: debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password debug1: No more authentication methods to try. Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password). Couldn't read packet: Connection reset by peer [sftpuser@XXX ~]$exit [root@XXX ssh]# grep sshd /var/log/secure [root@XXX ssh]#
hana_yama_san

2020/08/31 10:43

>>id_dsaを見に行っているようで、パスワード認証になっていないような気がしました。 あら、ほんとですね。でも、 debug1: Next authentication method: password sftpuser@172.168.0.7's password: と出力されて実際にパスワード入力後に Permission denied, please try again. と言われているんですよね。 念のため下記を入力して確認してみてください。 sftp -v -o PubkeyAuthentication=no sftpuser@172.168.0.7 で、パスワード入力後 Permission denied, please try again. と、なるなら・・・ そうですね、 chmod 755 /home/sftpuser chown root:root /home/sftpuser と、してみて試してもらえますか。
tequilla917

2020/08/31 12:29

上記コマンド実施しましたが変わらずですね・・・ 同じく「Permission denied, please try again.」が出力 権限変更後に再度「sftp -v -o PubkeyAuthentication=no sftpuser@172.168.0.7」しましたが、下記と同内容でした。(ログ長いので二回目の実施結果は記載していません) 「 /home/sftpuser」はオーナーsftpuserで良いような気がするのですが・・ [root@XXX ssh]#sftp -v -o PubkeyAuthentication=no sftpuser@172.168.0.7 OpenSSH_7.4p1, OpenSSL 1.0.2k-fips 26 Jan 2017 debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 58: Applying options for * debug1: Connecting to 172.168.0.7 [172.168.0.7] port 22. debug1: Connection established. debug1: permanently_set_uid: 0/0 debug1: identity file /root/.ssh/id_rsa type 1 debug1: key_load_public: No such file or directory debug1: identity file /root/.ssh/id_rsa-cert type -1 debug1: key_load_public: No such file or directory debug1: identity file /root/.ssh/id_dsa type -1 debug1: key_load_public: No such file or directory debug1: identity file /root/.ssh/id_dsa-cert type -1 debug1: key_load_public: No such file or directory debug1: identity file /root/.ssh/id_ecdsa type -1 debug1: key_load_public: No such file or directory debug1: identity file /root/.ssh/id_ecdsa-cert type -1 debug1: key_load_public: No such file or directory debug1: identity file /root/.ssh/id_ed25519 type -1 debug1: 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.4 debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4 debug1: match: OpenSSH_7.4 pat OpenSSH* compat 0x04000000 debug1: Authenticating to 172.168.0.7:22 as 'sftpuser' debug1: SSH2_MSG_KEXINIT sent debug1: SSH2_MSG_KEXINIT received debug1: kex: algorithm: curve25519-sha256 debug1: kex: host key algorithm: ecdsa-sha2-nistp256 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: kex: curve25519-sha256 need=64 dh_need=64 debug1: kex: curve25519-sha256 need=64 dh_need=64 debug1: expecting SSH2_MSG_KEX_ECDH_REPLY debug1: Server host key: ecdsa-sha2-nistp256 SHA256:DsxCuiE0PhLC2x3RpyCwvapUGt72f2wOYO1FZPo+98E debug1: Host '172.168.0.7' is known and matches the ECDSA host key. debug1: Found key in /root/.ssh/known_hosts:2 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: 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,gssapi-keyex,gssapi-with-mic,password debug1: Next authentication method: gssapi-keyex debug1: No valid Key exchange context debug1: Next authentication method: gssapi-with-mic debug1: Unspecified GSS failure. Minor code may provide more information No Kerberos credentials available (default cache: KEYRING:persistent:0) debug1: Unspecified GSS failure. Minor code may provide more information No Kerberos credentials available (default cache: KEYRING:persistent:0) debug1: Next authentication method: password sftpuser@172.168.0.7's password: debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password Permission denied, please try again. sftpuser@172.168.0.7's password: debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password Permission denied, please try again. sftpuser@172.168.0.7's password: debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password debug1: No more authentication methods to try. Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password). Couldn't read packet: Connection reset by peer [root@XXX ssh]# [root@XXX ssh]# chmod 755 /home/sftpuser [root@XXX ssh]# chown root:root /home/sftpuser [root@XXX ssh]#
hana_yama_san

2020/08/31 12:35

なんと、お力になれていない様で恐縮です。 ちなみに、このユーザのローカルログインや 単なるSSHとかscpは、どういう動作になるか試されましたか?
hana_yama_san

2020/08/31 12:47

おっと、 debug1: identity file /home/sftpuser/.ssh/id_rsa type 1 だったのが debug1: identity file /root/.ssh/id_rsa type 1になっていて、 それが >>二回目の実施結果は記載していません ということで、~homeのオーナーをrootに変える前に この出力が有ったと言うことですよね。 なんか、/etc/ssh/sshd_configのどこかに 邪魔な記載が有りそうな気がします。 (このユーザで公開キーを禁じた時点でrootユーザの  公開キーを見に行っている) ご確認を・・・
tequilla917

2020/09/01 00:21

こちらこそ、丁寧な回答ありがとうございます。 ssh、scpコマンドも同様に「Permission denied, please try again.」が出力されます。 そしてログを改めて確認してみたらsftpuserでsftpコマンド実施時には「debug1: identity file /sftpuser/.ssh/id_rsa type 1」になっておりユーザによって参照先が変化しているようでした。 以下にsshd_configの内容を記載致します。(主だった有効無効部分を記載) HostKey /etc/ssh/ssh_host_rsa_key #HostKey /etc/ssh/ssh_host_dsa_key HostKey /etc/ssh/ssh_host_ecdsa_key HostKey /etc/ssh/ssh_host_ed25519_key # Ciphers and keying #RekeyLimit default none # Logging #SyslogFacility AUTH SyslogFacility AUTHPRIV #LogLevel INFO # Authentication: #LoginGraceTime 2m #rootユーザでのログイン許可 PermitRootLogin yes #StrictModes yes #MaxAuthTries 6 #MaxSessions 10 #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 #AuthorizedPrincipalsFile none #AuthorizedKeysCommand none #AuthorizedKeysCommandUser nobody # To disable tunneled clear text passwords, change to no here! #PasswordAuthentication yes #PermitEmptyPasswords no # パスワード認証するかの有無 PasswordAuthentication yes # Change to no to disable s/key passwords #ChallengeResponseAuthentication yes ChallengeResponseAuthentication no # override default of no subsystems Subsystem sftp /usr/libexec/openssh/sftp-server # Example of overriding settings on a per-user basis #Match User anoncvs # X11Forwarding no # AllowTcpForwarding no # PermitTTY no # ForceCommand cvs server #sftpuserでのログインを許可する Match User sftpuser ChrootDirectory /home/sftpuser/ ForceCommand internal-sftp PasswordAuthentication yes
hana_yama_san

2020/09/01 13:34

うーん。 特段怪しいところは無さそうですね。 ただ、少し気になるのは >>#rootユーザでのログイン許可 >>PermitRootLogin yes ですか・・ 職場でsftpはよく使用していますし、 自宅でもssh,scpは日常茶飯事で使ってますが、 PermitRootLogin no しか設定したことが無いのです。 ダメモトで試してみてください。 あと、 >>ssh、scpコマンドも同様に と有りますが、ローカルログインはどうだったのでしょうか? ま、この辺で解決しなければ、今週末にでも 自宅のサーバにsftpを設定して検証します。
tequilla917

2020/09/02 02:01

PermitRootLogin noに変えてみてもやはり出来ませんでした。 そもそも「ssh sftpuser@172.168.0.9」を実施した際に、ECDSA key~と鍵認証について聞かれる自体、おかしいということですよね?
hana_yama_san

2020/09/02 11:59

確かに、 debug1: Host '172.168.0.7' is known and matches the ECDSA host key. debug1: Found key in /root/.ssh/known_hosts:2 というのは、 我が家の公開鍵認証のssh -v の出力と同じですね。 debug1: Host 'bxxxxx.yyyyy.local' is known and matches the ECDSA host key. debug1: Found key in /home/usr/.ssh/known_hosts:6  ※あ、でも何故か「/root/.ssh/known_hosts」を見に行っている。   変ですね。 ま、とりあえず週末には検証してみますので、 >>ローカルログインはどうだったのでしょうか? を確認してください(実はアカウントがロックされていましたとか、  トホホな結果でないことを確認することも重要です)
hana_yama_san

2020/09/06 05:41 編集

まずは、普通に設定してみました。 [usr@host]~> sftp -v sftpuser@r-host OpenSSH_7.8p1, OpenSSL 1.1.1d-freebsd 10 Sep 2019 debug1: Reading configuration data /home/hironobu/.ssh/config debug1: Reading configuration data /etc/ssh/ssh_config debug1: Connecting to r-host [172.16.11.226] port 22. debug1: Connection established. 〜中略〜 debug1: Local version string SSH-2.0-OpenSSH_7.8 FreeBSD-20180909 debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1_hpn13v11 FreeBSD-20140420 debug1: match: OpenSSH_6.6.1_hpn13v11 FreeBSD-20140420 pat OpenSSH_6.6.1* compat 0x04000002 debug1: Authenticating to bluemoon.minus-zero.local:22 as 'sftpuser' debug1: SSH2_MSG_KEXINIT sent debug1: SSH2_MSG_KEXINIT received debug1: kex: algorithm: curve25519-sha256@libssh.org debug1: kex: host key algorithm: ecdsa-sha2-nistp256 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: ecdsa-sha2-nistp256 SHA256:Lbv57hyyIe3AFffhV1aGp074xb+s5khqStjgGt5V1Xs DNS lookup error: general failure debug1: Host 'r-host' is known and matches the ECDSA host key. debug1: Found key in /home/hironobu/.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: SSH2_MSG_SERVICE_ACCEPT received debug1: Authentications that can continue: publickey,password,keyboard-interactive debug1: Next authentication method: publickey 〜略〜 debug1: Authentications that can continue: publickey,password,keyboard-interactive 〜中略〜 debug1: Next authentication method: keyboard-interactive Password for sftpuser@bluemoon.minus-zero.local: debug1: Authentication succeeded (keyboard-interactive). Authenticated to r-host ([172.16.11.226]:22). debug1: channel 0: new [client-session] debug1: Requesting no-more-sessions@openssh.com debug1: Entering interactive session. debug1: pledge: network debug1: Sending subsystem: sftp Connected to sftpuser@r-host. sftp> sshd_configのMatch User 部分はあなたのコンフィグからコピペしました。
hana_yama_san

2020/09/06 06:09 編集

次にsftpuserのアカウントをロックしてみます。 [root@r-host]~> pw lock sftpuser [root@r-host]~> exit logout [hyam@r-host]~> exit logout Connection to r-host closed. 〜前略〜 debug1: Next authentication method: keyboard-interactive Password for sftpuser@r-host: debug1: Authentications that can continue: publickey,password,keyboard-interactive Password for sftpuser@r-host: debug1: Authentications that can continue: publickey,password,keyboard-interactive Password for sftpuser@r-host: debug1: Authentications that can continue: publickey,password,keyboard-interactive debug1: Next authentication method: password sftpuser@r-host's password: debug1: Authentications that can continue: publickey,password,keyboard-interactive Permission denied, please try again. sftpuser@r-host's password: Received disconnect from 172.16.11.226 port 22:2: Too many authentication failures for sftpuser Disconnected from 172.16.11.226 port 22 Connection closed 似たような状況が再現されました。 grep sshd /var/log/auth.log Sep 6 14:45:58 r-host sshd[84399]: Received disconnect from 172.16.11.230: 11: disconnected by user Sep 6 14:46:14 r-host sshd[84427]: error: PAM: authentication error for sftpuser from host Sep 6 14:46:24 r-host sshd[84427]: error: PAM: authentication error for sftpuser from host Sep 6 14:46:24 r-host sshd[84427]: Postponed keyboard-interactive for sftpuser from 172.16.11.230 port 62177 ssh2 [preauth] Sep 6 14:46:33 r-host sshd[84427]: error: PAM: authentication error for sftpuser from host Sep 6 14:46:55 r-host sshd[84427]: Failed password for sftpuser from 172.16.11.230 port 62177 ssh2 Sep 6 14:47:05 r-host sshd[84427]: Failed password for sftpuser from 172.16.11.230 port 62177 ssh2 Sep 6 14:47:05 r-host sshd[84427]: Disconnecting: Too many authentication failures for sftpuser [preauth] grep sshd security 出力なし
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問