それではサーバーに入ってみましょう。
サーバーに入る
SSHクライアントソフトについて
サーバーに入るためにはSSHクライアントソフトが必要になります。
Macの場合は,最初から入っているターミナルでいいでしょう。(私はターミナル使いにくくて,MacでもWindowsのSSHクライアントソフトを使っています。)
Windowsの場合は次の2つが有名かと思います。

私は日本製ソフトが好きなのと,昔から使っていたこともあって,Tera Termにします。
初回ログイン
Tera Termを開くと,こんな画面が出て来ます。
取得したIPアドレス・22番ポートで入っていきます。
セキュリティ警告が出てくるので「続行」ボタンで進めていきます。
ユーザ名はroot,RSA/DSA/ECDSA鍵を使うにチェックを入れ,ログイン用認証キー作成したときの秘密鍵を選んで,OKを押して下さい。
これで入れます。
ポート番号の変更
22番ポートのままにしておくと,DoS攻撃を喰らう可能性が高くなりますので,ポート番号を変更するのが得策です。
カゴヤ・クラウド/VPSの場合は,49152 から 65535 は自由に使用できるポート番号として規定されています。
まずrootアカウントでログインします。
そして,例えば65535番ポートを設定したいときは,次のコマンドを入力します。
[root@v0000 ~]# iptables -A INPUT -p tcp --dport 65535 -j ACCEPT
iptablesの設定を反映させるため,次のコマンドを入力します。
[root@v0000 ~]# iptables-save > /etc/sysconfig/iptables
これだけだとポートを開けただけなので,SSH接続ポート番号を変更すべく,エディタを開きます。(私はnanoで行きます。現段階でvi使いこなせる自信がないですし,emacsも同様。)
なお,nanoのインストールはこのコマンドで。
[root@v0000 ~]# yum install nano
[root@v0000 ~]# nano /etc/ssh/sshd_config
エディタに[sshd_config]の内容が表示されますので,「#Port 22」という記述を探します。
# $OpenBSD: sshd_config,v 1.90 2013/05/16 04:09:14 dtucker 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:/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 override the # default value. # If you want to change the port on a SELinux system, you have to tell # SELinux about this change. # semanage port -a -t ssh_port_t -p tcp #PORTNUMBER # #Port 22 #AddressFamily any #ListenAddress 0.0.0.0 #ListenAddress ::
この「#Port 22」を「Port 65535」に変更します。
(注)行頭のコメントアウト「#」は削除して下さい。
# $OpenBSD: sshd_config,v 1.90 2013/05/16 04:09:14 dtucker 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:/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 override the # default value. # If you want to change the port on a SELinux system, you have to tell # SELinux about this change. # semanage port -a -t ssh_port_t -p tcp #PORTNUMBER # Port 65535 #AddressFamily any #ListenAddress 0.0.0.0 #ListenAddress ::
あとは保存するのみです。
保存したらsshdを再起動します。→うまくいかなかったのでインスタンス自体を再起動しました。
新しいポート番号で起動することを確認できたら終了です。
お疲れ様でした。
コマンドが通らない…。
restartコマンドだったり,netstatコマンドだったり,通らないんですよ…。
この原因を知りたいところです。
コメント