macOS SSHコマンドでサーバーに接続する方法

環境
macOS

操作方法
1.~/.ssh ディレクトリを作成します
mkdir ~/.ssh
所有者に読み・書き・実行権限を付与します
chmod 700 ~/.ssh

2.秘密鍵ファイルを移動します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
mv sample_id_rsa ~/.ssh/sample_id_rsa
chmod 400 ~/.ssh/sample_id_rsa
mv sample_id_rsa ~/.ssh/sample_id_rsa chmod 400 ~/.ssh/sample_id_rsa
mv sample_id_rsa ~/.ssh/sample_id_rsa
chmod 400 ~/.ssh/sample_id_rsa

3.~/.ssh/config ファイルを作成します
vi ~/.ssh/config
以下の内容を記載します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Host 接続名
HostName ホスト名
User ユーザー名
IdentityFile ~/.ssh/sample_id_rsa
Port ポート番号
TCPKeepAlive yes
IdentitiesOnly yes
Host 接続名 HostName ホスト名 User ユーザー名 IdentityFile ~/.ssh/sample_id_rsa Port ポート番号 TCPKeepAlive yes IdentitiesOnly yes
Host 接続名
HostName ホスト名
User ユーザー名
IdentityFile ~/.ssh/sample_id_rsa
Port ポート番号
TCPKeepAlive yes
IdentitiesOnly yes

所有者に読み・書き権限を付与します
chmod 600 ~/.ssh/config

4.SSH動作確認
ssh 接続名

IT

Posted by arkgame