MacターミナルからCentOSへssh接続時、公開鍵認証とタイムアウトしない設定
2012年06月06日
Macでの作業鍵ファイル「id_rsa」の作成
$ ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/Users/username/.ssh/id_rsa): #ディレクトリ作成場所の指定 変更しないのでそのままEnterを押す Enter passphrase (empty for no passphrase): # 任意のパスフレーズを入力 Enter same passphrase again: # パスフレーズ確認
保存されたファイルをMacの「Finder」で開く。
command+shift+Gでパスウィンドウが開き「~/.ssh」入力し「id_rsa.pub」をテキストエディタで開き中身をコピー。
CentOS側の作業
sshでホストにログインし、「.ssh」フォルダと「.ssh/authorized_keys」ファイルを作成しパーミッション設定をする。
$ mkdir .ssh $ chmod 700 .ssh $ touch .ssh/authorized_keys $ chmod 600 .ssh/authorized_keys
「.ssh/authorized_keys」にMacで作成した鍵ファイル「id_rsa.pub」の中身を貼付け。
$ vim .ssh/authorized_keys
Macの設定
configファイルの作成と設定
$ vi .ssh/config Host example Hostname www.example.com User user_name IdentityFile ~/.ssh/id_rsa ServerAliveInterval 60