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

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

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

Terminalは、Apple社のmacOSに標準で付属しているUNIX端末エミュレータ。UNIXコマンドによってMacの操作および設定を行うことができます。

SSH

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

Webサーバー

Webサーバーとは、HTTPリクエストに応じて、クライアントに情報を提供するシステムです。

Q&A

解決済

1回答

1902閲覧

Xserverへの接続がConnection closedとでてできない。

ex025

総合スコア179

terminal

Terminalは、Apple社のmacOSに標準で付属しているUNIX端末エミュレータ。UNIXコマンドによってMacの操作および設定を行うことができます。

SSH

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

Webサーバー

Webサーバーとは、HTTPリクエストに応じて、クライアントに情報を提供するシステムです。

0グッド

0クリップ

投稿2020/08/21 15:46

編集2020/08/21 15:48

#やりたいこと
macOSのターミナルからSSH接続でXserverに接続し、コマンドを使用してxserverを操作したい。

#やったこと
0. XserverのサイトでSSHをオンにする。
0. Xserverのサイトで秘密鍵、公開鍵を生成し、秘密鍵を「id_xsrv_rsa」として「~/.ssh/」にダウンロード
0. 以下のコマンドを実行

$ chmod 700 ~/.ssh $ chmod 600 ~/.ssh/id_xsrv_rsa $ ssh -l [サーバーID] -i id_xsrv_rsa [サーバーID].xsrv.jp -p 10022

サーバーID、パスワードはあっているはずです。
以下のサイトを参考にしました。
エックスサーバーにssh接続する方法(ターミナル利用)

#問題点
Connection closed by 183.181.83.76 port 10022
となって接続できないです。

以前CyberduckからFTPSで接続しようとした時にもどうしても弾かれたので、サーバー側の設定の問題だと思いますが、思い当たるものがありません。
それからは結局諦めて、xserverのサイトからファイル操作をしていました。

どのような可能性があるのか、教えて欲しいです。

#環境
######ローカル
macOS Catalina 10.15.6
######サーバー
Xserver

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

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

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

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

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

dameo

2020/08/22 05:43

xserverは使ったことありませんが、こういう問題を解決するときには、必ずエラーコードやメッセージなどを詳細に記述する必要があります。また、純粋な環境系の問題は、「プログラミングと全く関係ない」と個人的に思っているので、回答もしたくはないです。 というのは置いといて、まずはsshに-vオプションを付けてエラーログを貼ってください。個人情報や鍵の情報っぽいのは隠してくださいね。
dameo

2020/08/22 05:47

っていうか、sshのオプションおかしくないですか? ssh -p ポート ユーザーID@サーバーFQDN とかで行けますよ。 xserverってそんな変なポート使ってるんですか?
ex025

2020/08/22 10:03 編集

OpenSSH_8.1p1, LibreSSL 2.7.3 debug1: Reading configuration data /Users/[ユーザー名]/.ssh/config debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 47: Applying options for * debug1: Connecting to [サーバーID].xsrv.jp port 10022. debug1: Connection established. debug1: identity file id_xsrv_rsa type -1 debug1: identity file id_xsrv_rsa-cert type -1 debug1: Local version string SSH-2.0-OpenSSH_8.1 debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4 debug1: match: OpenSSH_7.4 pat OpenSSH_7.0*,OpenSSH_7.1*,OpenSSH_7.2*,OpenSSH_7.3*,OpenSSH_7.4*,OpenSSH_7.5*,OpenSSH_7.6*,OpenSSH_7.7* compat 0x04000002 debug1: Authenticating to [サーバーID].xsrv.jp:10022 as '[サーバーID]' 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: expecting SSH2_MSG_KEX_ECDH_REPLY debug1: Server host key: ecdsa-sha2-nistp256 SHA256:V0GmZVuUlP6tQw5MYbGelfcq+IQwq/6+HnH1OPAcaLo debug1: Host '[[サーバーID].xsrv.jp]:10022' is known and matches the ECDSA host key. debug1: Found key in /Users/[ユーザー名]/.ssh/known_hosts:1 debug1: rekey out after 134217728 blocks debug1: SSH2_MSG_NEWKEYS sent debug1: expecting SSH2_MSG_NEWKEYS debug1: SSH2_MSG_NEWKEYS received debug1: rekey in after 134217728 blocks debug1: Will attempt key: id_xsrv_rsa explicit 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 debug1: Next authentication method: publickey debug1: Trying private key: id_xsrv_rsa Enter passphrase for key 'id_xsrv_rsa': Connection closed by 183.181.83.76 port 10022
ex025

2020/08/22 09:55

xserverのポートは10022だそうです。公式サイトに書いてあります。
dameo

2020/08/22 10:41

公開鍵認証をしようとしてるようですが、公開鍵を送っていません。 最初の方のログの debug1: identity file id_xsrv_rsa type -1 debug1: identity file id_xsrv_rsa-cert type -1 もおかしいです。 打ち込んだをコマンドを書いてもらってもいいですか?
ex025

2020/08/22 10:42

ssh -v -l [サーバーID] -i id_xsrv_rsa [サーバーID].xsrv.jp -p 10022 です。
dameo

2020/08/22 10:55

サーバーIDがユーザーIDなんですね for f in ~/.ssh/*;do echo -n "${f}:";file $f;done を実行して貼ってもらえますか? ユーザー名部分出ちゃうと思うので隠してくださいね
ex025

2020/08/22 11:00 編集

/Users/[ユーザー名]/.ssh/config:/Users/[ユーザー名]/.ssh/config: ASCII text /Users/[ユーザー名]/.ssh/id_xsrv_rsa:/Users/[ユーザー名]/.ssh/id_xsrv_rsa: PEM RSA private key /Users/[ユーザー名]/.ssh/known_hosts:/Users/[ユーザー名]/.ssh/known_hosts: ASCII text, with very long lines です。
dameo

2020/08/22 11:09

ssh-keygen -y ~/.ssh/id_xsrv_rsa の実行結果はどうなりますか?公開鍵が入ってれば出てくるはずなんですが… 結果はエラーでなければ先頭と最後だけで中身貼らなくていいです
ex025

2020/08/22 11:14

Too many arguments. usage: ssh-keygen [-q] [-b bits] [-C comment] [-f output_keyfile] [-m format] [-N new_passphrase] [-t dsa | ecdsa | ed25519 | rsa] ... ssh-keygen -Y verify -f allowed_signers_file -I signer_identity -n namespace -s signature_file [-r revocation_file] と出ます。
dameo

2020/08/22 11:20

あ、間違えましたすみません。 ssh-keygen -y -f ~/.ssh/id_xsrv_rsa
ex025

2020/08/22 11:22

Enter passphrase: ssh-rsa ... 問題なく出力されています
dameo

2020/08/22 11:34

とりあえずUbuntuの環境だとですね file 秘密鍵 のときに OpenSSH private key とか file 公開鍵 のときに OpenSSH RSA public key とか出るんですよ。 少なくともfileコマンドは違う形式と認識と判断してる可能性が高いです。 ここからはさらに推測ですが、公開鍵が含まれてたとしても、送れてないとなると少なくとも形式は変換した方がいいと思います。ssh-keygenのデフォだと、 ~/.ssh/id_rsa に秘密鍵が ~/.ssh/id_rsa.pub に公開鍵が入ります。 なので、先程の結果を ssh-keygen -y -f ~/.ssh/id_xsrv_rsa > ~/.ssh/id_xsrv_rsa.pub とかしたら存外行ってしまうかもしれません あと、ssh-keygenで作ってない鍵を使ってるんならそれは「絶対に」書かないと駄目ですよ。
dameo

2020/08/22 11:43

あ、生成方法は書いてありましたね。ごめんなさい。
dameo

2020/08/22 11:46

あと、パスフレーズの入力があったので、公開鍵送られてないって思ってましたが、そもそも秘密鍵とセットのままの形式だと、公開鍵取り出すのにパスフレーズが必要だったのかもしれません。 他の方の記述などを見るに、わざわざ公開鍵用のファイルを作ってないので、パスフレーズを間違えてる可能性がありますね。
ex025

2020/08/22 11:47

ssh-keygen -y -f ~/.ssh/id_xsrv_rsa > ~/.ssh/id_xsrv_rsa.pub を実行しました。 その後、解決はしていませんが、さきほどとsshのログが変わったので書きます。 $ ssh -v -l [サーバーID] -i id_xsrv_rsa [サーバーID].xsrv.jp -p 10022 OpenSSH_8.1p1, LibreSSL 2.7.3 debug1: Reading configuration data /Users/[ユーザー名]/.ssh/config debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 47: Applying options for * debug1: Connecting to [サーバーID].xsrv.jp port 10022. debug1: Connection established. debug1: identity file id_xsrv_rsa type 0 debug1: identity file id_xsrv_rsa-cert type -1 debug1: Local version string SSH-2.0-OpenSSH_8.1 debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4 debug1: match: OpenSSH_7.4 pat OpenSSH_7.0*,OpenSSH_7.1*,OpenSSH_7.2*,OpenSSH_7.3*,OpenSSH_7.4*,OpenSSH_7.5*,OpenSSH_7.6*,OpenSSH_7.7* compat 0x04000002 debug1: Authenticating to [サーバーID].xsrv.jp:10022 as '[サーバーID]' 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: expecting SSH2_MSG_KEX_ECDH_REPLY debug1: Server host key: ecdsa-sha2-nistp256 SHA256:V0GmZVuUlP6tQw5MYbGelfcq+IQwq/6+HnH1OPAcaLo debug1: Host '[[サーバーID].xsrv.jp]:10022' is known and matches the ECDSA host key. debug1: Found key in /Users/[ユーザー名]/.ssh/known_hosts:1 debug1: rekey out after 134217728 blocks debug1: SSH2_MSG_NEWKEYS sent debug1: expecting SSH2_MSG_NEWKEYS debug1: SSH2_MSG_NEWKEYS received debug1: rekey in after 134217728 blocks debug1: Will attempt key: id_xsrv_rsa RSA SHA256:+ZSBIZe03NGTEHYyowFG91nPDia20OJ/OwmABo3x0Fk explicit 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 debug1: Next authentication method: publickey debug1: Offering public key: id_xsrv_rsa RSA SHA256:+ZSBIZe03NGTEHYyowFG91nPDia20OJ/OwmABo3x0Fk explicit debug1: Server accepts key: id_xsrv_rsa RSA SHA256:+ZSBIZe03NGTEHYyowFG91nPDia20OJ/OwmABo3x0Fk explicit Enter passphrase for key 'id_xsrv_rsa': Connection closed by 183.181.83.76 port 10022
dameo

2020/08/22 11:47

ちなみに先程のssh-keygen -y -f ...ではパスフレーズ聞かれましたか?
ex025

2020/08/22 11:49

聞かれました。 パスフレーズ間違えると別のエラーになるので、パスフレーズは合っているはずです。
dameo

2020/08/22 11:54

公開鍵送られましたね。まさかとは思いますが、XServerのWeb画面のssh設定で、sshを有効にしてないとかそういう可能性はないですよね?
ex025

2020/08/22 11:57

そのまさかでした! 設定がうまく保存できていませんでした。 こんな初歩的なミスとは。 こんなことで貴重な時間を使わせてしまって、申し訳ありません。
dameo

2020/08/22 12:00

なるほど。まあ言われないと気付かないこともあるでしょう。 何にせよ使えるようになってよかったです。
ex025

2020/08/22 12:01

あと、id_xsrv_rsa.pubはなくても大丈夫でした。
ex025

2020/08/22 12:02

ありがとうございました。
guest

回答1

0

自己解決

XserverのSSHをONにした時に、うまく保存できていませんでした。

dameoさん、こんなことに時間を使わせてしまって申し訳ありません。

投稿2020/08/22 12:01

ex025

総合スコア179

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問