3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

SSH設定(OpenSSH SSH2)

Last updated at Posted at 2016-05-22

ssh 設定ファイル

sshサーバ設定
/etc/ssh/sshd_conf

現在の設定がどうなっているかは、以下のコマンドで確認

cat sshd_config | 
grep -v -e '^\s*#' -e  '^s*$'
設定値 意味
Port 22 sshが使用するポート。iptablesで開けておくこと。22以外の値に変更したほうがよい
Protocol 2 複数のバージョンを指定することもできるが、優先順位を示すものではない。Protocol 2,1なら、ver2,ver1の接続を許可、2だけだと、ver2のみでの接続を許可する
HostKey 秘密鍵が格納されるファイル。ver2なら、/etc/ssh/ssh_host_rsa_keyが使用される
Pubkey
Authentication
yes
公開鍵認証をONにするかどうか。Protocol Ver2にのみ適用される
PermitRoot
Login no
rootでのログインを許可しない
Password
Authentication no
パスワード認証を許可するかどうか(default yes)

SSH公開鍵認証に何回もはまったので

(OpenSSH SSH2で認証する場合)

1.Linux側で鍵を作成する(ログインユーザで作成)

$cd
$pwd
/home/user1
$mkdir ./.ssh  '.sshフォルダを作成する
$chmod 700 ./.ssh 'パーミッションを700に
$cd ./.ssh
$ssh-keygen -t rsa '鍵を作成
$cp -p id_rsa.pub authorized_keys '公開鍵の名前を変更
$chmod 600 authorized_keys 'パーミッションを600に
$ls -l 'こんな感じ id_rsa.pubは消してよい
-rw------- 1 user1 user1  417 authorized_keys
-rw------- 1 user1 user1 1700 id_rsa
-rw------- 1 user1 user1  417 id_rsa.pub
$cd /home
$ls -l 'ちなみに/home/userもパーミッション700にしておくこと
drwx------ 3 user1 user1 3800 May 20 13:00 user1
$su - 'ここからはrootで作業
※作った鍵は/etc/ssh/ssh_host_rsa_keyにも保存しておくこと
$cd /etc/ssh
$cat sshd_config | grep -v -e '^\s*#' -e '^s*$'
Port 8888 '22以外に変更しておいたほうがよい
Protocol 2 'SSH2で認証
HostKey /etc/ssh/ssh_host_rsa_key
PermitRootLogin no 'ルートでのログイン不可
RSAkeyAuthentication yes 'RSAでの認証をONに
PubkeyAuthentication yes '公開鍵認証をONに
AuthorizedKeyFile    .ssh/authorized_keys '認証ファイル指定
PasswordAuthentication no 'ここはNOに。ただし、SSHを設定する前に秘密鍵ファイルをtelnetとかscpで送っておきたいときは、yesにしておかないと送りようがない
UsePAM no
UsePrivilegeSeparation sandbox
Subsystem   sftp /usr/libexec/openssh/sftp-server
#
# /etc/init.d/sshd restart 'sshd再起動で設定反映

公開鍵をwindowsに落とす(putty使用)
これで秘密鍵を落とす時は、PasswordAuthentication yesにしておくこと

>cd "C:\Plogram Files\PuTTY" 'puttyのフォルダに移動
>pscp -scp -P 8888 user1@192.168.111.111:/home/user1/id_rsa C:\Users/user1
id_rsa     |0Kb| 0.4Kbs|ETA 00:00:00 | 100%

落としたid_rsaはputtygenを使って
変換→鍵のインポート→秘密鍵の保存
でputty形式に変換して保存

保存したputty形式の鍵を、
puttyの左ウィンドウ
SSH→認証→認証のためのプライベートキーファイル→参照
で指定する

3
2
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
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?