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

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

新規登録して質問してみよう
ただいま回答率
85.48%
さくらのVPS

さくらのVPSは、さくらインターネット社が提供するVPS(仮想専用サーバー)です。高速なSSDの選択や複数台構成も可能。利用者に応じた柔軟なプランが用意されています。大規模システムにも対応可能なスケーラビリティを備えたホスティングサービスです。

SSH

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

ログイン

ログインは、ユーザーがコンピューターシステムにアクセスするプロセスの事を呼びます。

Q&A

解決済

2回答

1241閲覧

さくらのVPSでSSHのポート番号を変えたらログインできなくなった。

pro88

総合スコア17

さくらのVPS

さくらのVPSは、さくらインターネット社が提供するVPS(仮想専用サーバー)です。高速なSSDの選択や複数台構成も可能。利用者に応じた柔軟なプランが用意されています。大規模システムにも対応可能なスケーラビリティを備えたホスティングサービスです。

SSH

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

ログイン

ログインは、ユーザーがコンピューターシステムにアクセスするプロセスの事を呼びます。

0グッド

0クリップ

投稿2019/07/20 07:51

環境
さくらのVPS CentOS 6.10

以前よりさくらのVPSを利用しておりましたが、SSDのサーバに変更しようと考えて
二週間お試しを利用して、サーバのセットアップをしようとしましたところ
公開鍵設定の設定を完了し、鍵認証でログイン出来ることを確認後にSSHのポート番号を
任意の番号に変更して、iptables の設定もポート番号をしたのですが、その後
Tera Term からログインしようとしたところ「ホストに接続できません」と接続できません。

その状態で変更したポート番号を削除して、Tera Term からポート番号22番でログインを
試すと、普通に鍵認証でログインできてしまうのです。

ポート番号を任意の番号に変更してログインを試すと何回試しても「ホストに接続できません」で
22番では認証できてしまいます。
パーミッションも以下で設定しております。
chmod 0700 .ssh
chmod 0600 .ssh/authorized_keys

以前から、さくらのVPSをふたつ契約してやりますが、このようなことが無かったために
ご助言を頂ければと思います。
宜しくお願いいたします。

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

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

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

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

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

guest

回答2

0

さくらに問い合わせてみましたところ、以前と違いOSの再インストールをするとデフォルトで22番ポートだけが開かれている状態で、それを回避するには、コントロールパネルのサーバ情報の一番右のタブで「パケットフィルタ」部分を開くと設定を変更することができました。
OSの再インストールをすると22番ポートしか開いてないので、もちろん80番も閉じられておりWEBにアクセスすることもできない状態です。
とりあえずこれで解決しました。
コメントくださいました方々、お手数をおかけしまして申し訳ありませんでした。

投稿2019/07/22 01:30

pro88

総合スコア17

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

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

pro88

2019/07/24 04:40

その通りです。参りました。 リンクを張っていただきましてありがとうございます。
guest

0

ベストアンサー

sshd_configの設定を間違えている、又はsshdを再起動していないだけではないでしょうか?
もし、間違いでない場合は、設定内容も質問に書いてもらえますか。

投稿2019/07/20 08:13

scsi

総合スコア2840

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

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

hentaiman

2019/07/20 08:20

iptablesのポートも変更してるのに22でつながるっていうんだからiptablesは確実に反映されてないですね
pro88

2019/07/20 09:26

scsiさん ご連絡ありがとうございます。 sshdとiptablesの再起動は、設定変更のたびに行っております。 以下がsshd_configの設定です # cat /etc/ssh/sshd_config # $OpenBSD: sshd_config,v 1.80 2008/07/02 02:24:18 djm Exp $ # This is the sshd server system-wide configuration file. See # sshd_config(5) for more information. # This sshd was compiled with PATH=/usr/local/bin:/bin:/usr/bin # The strategy used for options in the default sshd_config shipped with # OpenSSH is to specify options with their default value where # possible, but leave them commented. Uncommented options change a # default value. Port 12120 #AddressFamily any ListenAddress 0.0.0.0 #ListenAddress :: # Disable legacy (protocol version 1) support in the server for new # installations. In future the default will change to require explicit # activation of protocol 1 Protocol 2 # HostKey for protocol version 1 #HostKey /etc/ssh/ssh_host_key # HostKeys for protocol version 2 #HostKey /etc/ssh/ssh_host_rsa_key #HostKey /etc/ssh/ssh_host_dsa_key # Lifetime and size of ephemeral version 1 server key #KeyRegenerationInterval 1h #ServerKeyBits 1024 # Logging # obsoletes QuietMode and FascistLogging #SyslogFacility AUTH SyslogFacility AUTHPRIV #LogLevel INFO # Authentication: #LoginGraceTime 2m #PermitRootLogin yes #StrictModes yes #MaxAuthTries 6 #MaxSessions 10 #RSAAuthentication yes PubkeyAuthentication yes AuthorizedKeysFile .ssh/authorized_keys #AuthorizedKeysCommand none #AuthorizedKeysCommandRunAs nobody # For this to work you will also need host keys in /etc/ssh/ssh_known_hosts #RhostsRSAAuthentication no # similar for protocol version 2 #HostbasedAuthentication no # Change to yes if you don't trust ~/.ssh/known_hosts for # RhostsRSAAuthentication and HostbasedAuthentication #IgnoreUserKnownHosts no # Don't read the user's ~/.rhosts and ~/.shosts files #IgnoreRhosts yes # To disable tunneled clear text passwords, change to no here! #PasswordAuthentication yes #PermitEmptyPasswords no #PasswordAuthentication yes PasswordAuthentication no # Change to no to disable s/key passwords #ChallengeResponseAuthentication yes ChallengeResponseAuthentication no # Kerberos options #KerberosAuthentication no #KerberosOrLocalPasswd yes #KerberosTicketCleanup yes #KerberosGetAFSToken no #KerberosUseKuserok yes # GSSAPI options #GSSAPIAuthentication no GSSAPIAuthentication yes #GSSAPICleanupCredentials yes GSSAPICleanupCredentials yes #GSSAPIStrictAcceptorCheck yes #GSSAPIKeyExchange no # Set this to 'yes' to enable PAM authentication, account processing, # and session processing. If this is enabled, PAM authentication will # be allowed through the ChallengeResponseAuthentication and # PasswordAuthentication. Depending on your PAM configuration, # PAM authentication via ChallengeResponseAuthentication may bypass # the setting of "PermitRootLogin without-password". # If you just want the PAM account and session checks to run without # PAM authentication, then enable this but set PasswordAuthentication # and ChallengeResponseAuthentication to 'no'. #UsePAM no UsePAM yes # 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 #AllowAgentForwarding yes #AllowTcpForwarding yes #GatewayPorts no #X11Forwarding no X11Forwarding yes #X11DisplayOffset 10 #X11UseLocalhost yes #PrintMotd yes #PrintLastLog yes #TCPKeepAlive yes #UseLogin no #UsePrivilegeSeparation yes #PermitUserEnvironment no #Compression delayed #ClientAliveInterval 0 #ClientAliveCountMax 3 #ShowPatchLevel no #UseDNS yes #PidFile /var/run/sshd.pid #MaxStartups 10:30:100 #PermitTunnel no #ChrootDirectory none # no default banner path #Banner none # 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 # ForceCommand cvs server 以下がiptablesの設定です # cat /etc/sysconfig/iptables # Generated by iptables-save v1.4.7 on Sat Jul 20 14:12:01 2019 *filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT -A INPUT -p icmp -j ACCEPT -A INPUT -i lo -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 12120 -j ACCEPT -A INPUT -j REJECT --reject-with icmp-host-prohibited -A FORWARD -j REJECT --reject-with icmp-host-prohibited COMMIT # Completed on Sat Jul 20 14:12:01 2019 ご確認いただきましてご意見を頂ければと思います。 宜しくお願いいたします。
pro88

2019/07/20 09:31

hentaimanさん ご連絡ありがとうございます。 22で繋がるときは、もちろんsshd_configもiptablesどちらも22にしているからログイン出来ているということです。 任意のポート番号に変えた時だけがつながらないということです。 宜しくお願いいたします。
scsi

2019/07/20 09:34

sshdの再起動、iptablesの設定は反映はしましたか?
hentaiman

2019/07/20 09:36

という事はポート変更して接続できなったら仮想コンソールからログインしてポートを元に戻していたという事ですか?
pro88

2019/07/20 09:37

hentaimanさん はい、その通りです。シリアルコンソールから変更しております。
pro88

2019/07/20 09:38

scsiさん はい、どちらも再起動しております。
scsi

2019/07/20 09:41

netstat -anp | grep ssh iptables -L の結果を見せていただけますか
hentaiman

2019/07/20 09:46

仮想コンソールで/var/log/secure見ながら確認した方が早そうだなー。その際はついでにiptablesのlogも出しましょう。
pro88

2019/07/20 10:10 編集

scsiさん # netstat -anp | grep ssh tcp 0 0 0.0.0.0:12120 0.0.0.0:* LISTEN 4880/sshd tcp 0 0 133.167.89.183:41924 133.167.89.183:22 ESTABLISHED 4541/ssh tcp 0 0 133.167.89.183:12120 133.167.89.183:42952 ESTABLISHED 4899/sshd tcp 0 0 133.167.89.183:12120 133.167.89.183:42950 ESTABLISHED 4883/sshd tcp 0 0 133.167.89.183:22 133.167.89.183:41924 ESTABLISHED 4542/sshd tcp 0 0 133.167.89.183:42950 133.167.89.183:12120 ESTABLISHED 4882/ssh tcp 0 0 133.167.89.183:42952 133.167.89.183:12120 ESTABLISHED 4898/ssh unix 2 [ ] DGRAM 40875 4899/sshd unix 2 [ ] DGRAM 40763 4883/sshd unix 2 [ ] DGRAM 37296 4542/sshd # iptables -L Chain INPUT (policy ACCEPT) target prot opt source destination ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED ACCEPT icmp -- anywhere anywhere ACCEPT all -- anywhere anywhere ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:12120 REJECT all -- anywhere anywhere reject-with icmp-host-prohibited Chain FORWARD (policy ACCEPT) target prot opt source destination REJECT all -- anywhere anywhere reject-with icmp-host-prohibited Chain OUTPUT (policy ACCEPT) target prot opt source destination 以上です。 宜しくお願いします。
scsi

2019/07/20 10:15

設定は正しそうなので、別のサーバにアクセスしてませんか?
pro88

2019/07/20 10:28

scsiさん 設定は問題ないと思われるのですね。 お試しの申し込みなので、別のサーバで試してみようと考えますが、今コンソールから以下たたくと # ssh -p 12120 root@133.167.89.183 Permission denied (publickey,gssapi-keyex,gssapi-with-mic). となりますが、これはパーミッションの問題でしょうか? ただ、最初質問に書いた通り chmod 0700 .ssh chmod 0600 .ssh/authorized_keys なのですが。
scsi

2019/07/20 10:45 編集

お試しはポート変更するとアクセスできないですよ。私も1回ハマりました。
pro88

2019/07/20 10:49

scsiさん えっ!そうでしたか。 現在稼働中のサーバはもう本契約してから5年以上なりますけど、当初同じようにお試しから同じようにポート変更して使って、その後に本契約してたものですから、現在もそうだと思っていました。 現在はその仕様になっているのですね。分かりました。お手数をおかけしました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問