SSH

sshの設定めも

設定ファイル

/etc/ssh/sshd_config

下記なかんじでとりあえずなセキュアな設定

Port 22200 #22だと攻撃多すぎでログがいっぱいになるので変更。
 
PermitRootLogin no #root でログインできないようにする。
 
ChallengeResponseAuthentication no  #S/KeyとOPIEを使った認証を禁止
passwordsPasswordAuthentication no  #パスワード認証を禁止
 
AllowUsers auser  #ログインできるユーザーを指定する
#DenyUsers duser #ログインを禁止するユーザを指定する
#AllowGroups agroup    #ログインできるグル−プを指定する
#DenyGroups dgroup     #ログインを禁止するグループを指定する

公開鍵の作成

鍵はセキュリティ上、クライアントホスト側で作成する。
鍵がなきゃログインできないように設定してるんでパスフレーズはなし。たぶん大丈夫。
ファイル名を指定しないとid_rsa(秘密鍵),id_rsa.pub(公開鍵)ができる

$ ssh-keygen -t rsa  #-tでrsa(ssh2) -f でファイル名を指定する
 
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/user/.ssh/id_rsa):
Enter passphrase (empty for no passphrase): #パスフレーズ入力だけど何も入力せずEnter
Enter same passphrase again: #確認 ここも何も入力しない
Your identification has been saved in id_rsa.
Your public key has been saved in id_rsa.pub.
The key fingerprint is:

公開鍵の登録

USBかなにかで公開鍵をサーバホスト側にこぴー
パーミッションを600に

$ mkdir .ssh
$ chmod 700 .ssh  #この設定も必要
$ cp /media/USB/id_rsa.pub ~/.ssh/authorized_keys
$ chmod 600 ~/.ssh/authorized_keys

他の鍵を追加するときは

$ cat /media/USB/id_rsa2.pub >> ~/.ssh/authorized_keys

.ssh/configを設定していないと lftpでsftpするときはローカルの鍵はid_rsa、リモート側はauthorized_keysじゃないとうまくいきませんでした。

多段SSH

踏み台にするproxy-sというサーバにp-userでログインして、その先のa-serverにfugahogaというユーザーでログインする場合。
ProxyCommandForwardAgentが必須?

Host proxy-s
 Hostname xxx.xxx.xxx.xxx
 User p-user
 IdentityFile ~/.ssh/id_rsa_proxy
 
Host a-server
  Hostname zzz.zzz.zzz.zzz
  User fugahoga
  IdentityFile ~/.ssh/id_rsa_proxy
  ProxyCommand nohup ssh -q proxy-s nc -w 11 %h %p
  ForwardAgent yes
  ServerAliveInterval 60
server/ssh.txt · 最終更新: 2013/11/25 15:14 by eiji