LoginSignup
4
4

More than 5 years have passed since last update.

MacからCentOS7へSSH接続するためにやった事

Last updated at Posted at 2016-05-04

CentOS7(RHEL7)からsystemctlコマンド(systemd)とfirewall-cmdコマンド(firewalld・・内部的にはiptablesらしい)が一級市民になってるので慣れないといけない。

ポート番号の変更

49152とかに変更する。セキュリティのためというより、そのままだと/var/log/secureが見づらくなるというのが私の動機として大きい。

firewalldの設定

/etc/ssh/sshd_config

Port 49152

クライアント(Mac)側で鍵生成

cd .ssh
ssh-keygen -t rsa -f hoge
scp ~/.ssh/hoge.pub username@servername:

クライアント(Mac)側で接続設定

cd .ssh
vi config
Host hoge
 HostName servername
 Port 49152
 User username
 IdentityFile ~/.ssh/hoge

サーバ(CentOS)側で鍵登録

ssh servername
cat hoge.pub >> .ssh/authorized_keys

SSH2のみ許可

/etc/ssh/sshd_config

Protocol 2

公開鍵認証のみ許可

/etc/ssh/sshd_config

PasswordAuthentication no
GSSAPIAuthentication no

rootでの接続を禁止し、特定のユーザのみSSH接続を許可

/etc/ssh/sshd_config

PermitRootLogin no
AllowUsers username

再起動

systemctl restart sshd

再起動後、接続確認がとれるまでは既存セッションを切らないほうが良い。

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4