SSH入門

トップ > SSH入門

インストール

CentOS 7 の場合の手順を下記に示します。

Shell
# yum install -y openssh-clients
# yum install -y openssh-server
# systemctl enable sshd
# systemctl start sshd

Rootログインを禁止する

下記を変更後、sshd を再起動してください。

/etc/ssh/sshd_config
PermitRootLogin no

公開鍵でログインする

ローカルホストで鍵ペアを作成し、公開鍵をリモートホストに転送します。秘密鍵にパスフレーズをつけることもできます。

Shell
[yamada@local_host ~]# ssh-keygen -t rsa -b 2048
[yamada@local_host ~]# find ~/.ssh
.ssh/id_rsa              # 秘密鍵
.ssh/id_rsa.pub          # 公開鍵
[yamada@local_host ~]# scp .ssh/id_rsa.pub yamada@remote_host:

リモートホストで公開鍵を登録します。.ssh ディレクトリのパーミッションは 700、オーナーはログインユーザのものにしてください。

Shell
[yamada@remote_host ~]# mkdir ~/.ssh
[yamada@remote_host ~]# mv ~/id_rsa.pub ~/.ssh/authorized_keys
[yamada@remote_host ~]# chmod 700 ~/.ssh

ローカルから鍵を使用して SSH 接続します。

Shell
[yamada@local_host ~]# ssh remote_host

-i オプションで鍵ファイルを指定することもできます。

Shell
[yamada@local_host ~]# ssh -i ~/.ssh/id_rsa_123 remote_host

Copyright (C) 2020 杜甫々
初版:2020年4月26日、最終更新:2020年4月26日
http://www.tohoho-web.com/ex/ssh.html