Diary

Self training to output someting

SSH(鍵交換方式)

ssh接続の鍵交換方式での手順

 

参考URL

http://webkaru.net/linux/ssh-keygen-command/

 

前提

sshのパッケージをインストールしていること

yum -y ssh

 

鍵の生成

ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/karuma/.ssh/id_rsa): ← Enterキー
Created directory '/home/karuma/.ssh'. ← ~/.ssh がない場合、ディレクトリを作成
Enter passphrase (empty for no passphrase): パスフレーズを入力
Enter same passphrase again: ← もう一度パスフレーズを入力
Your identification has been saved in /home/karuma/.ssh/id_rsa.
Your public key has been saved in /home/karuma/.ssh/id_rsa.pub.

 

鍵の確認

ls ~/.ssh
id_rsa  id_rsa.pub

 

鍵使用時のパスコードの設定

ssh-keygen -p
Enter file in which the key is (/home/karuma/.ssh/id_rsa): ← Enterキー
Enter old passphrase: ← 古いパスフレーズを入力
Key has comment '/home/karuma/.ssh/id_rsa'
Enter new passphrase (empty for no passphrase): ← 新しいパスフレーズを入力
Enter same passphrase again: ← もう一度、新しいパスフレーズを入力
Your identification has been saved with the new passphrase.

※ここは面倒なので省いた

 ちなみに、鍵作成時のパスも省略している

 

公開鍵の設定、適用

ssh-keygen -i -f id_rsa.pub >> authorized_keys

※実際に使用したコマンドは

cat /~/.ssh/id_rsa_pub > authoraized_keys

 

パーミッションの設定

chmod 700 authorized_keys

chmod 600 id_rsa

 

ファイルの設定

/etc/ssh/sshd_config

適用設定はこのファイルの設定で変更

 

鍵を渡す

鍵交換コマンド

使い方参考URL

http://webkaru.net/linux/scp-command/