#freeze
* [[ssh]]
SSHを使うことにより、暗号化通信、サーバ認証、通信パケットの完全性の保障がされます。teratermを使いたいところですが、ssh2に対応させたい場合は、puttyを使います。もしくはhttp://sleep.mat-yan.jp/~yutaka/windows/index.htmlを使いましょう。今はこれを使ってます。これを知らなかった為にわざわざSSH1でやってたんですが、その必要はありません。SSH2でいきましょう。

#contents
** インストール
ftp://ftp.kddlabs.co.jp/OpenBSD/OpenSSH/portable/からOpenSSHをダウンロードします。openssh-3.9p1.tar.gzをダウンロードしました。これを入れる前にOpenSSL,zlib,Tcp Wrappersを入れておきます。
http://www.openssl.org/source/からOpenSSLをダウンロードします。
 wget http://www.openssl.org/source/openssl-0.9.7g.tar.gz
 tar xzvf openssl-0.9.7g.tar.gz
 cd openssl-0.9.7g
 ./config --prefix=/usr/local
 make 
 make install
ではzlibは[[PHP]]の時にいれたので、Tcp Wrappersをインストールします。サービスのアクセスログを採る事ができます。
http://ftp.porcupine.org/pub/security/index.htmlからダウンロードしました。
 wget http://ftp.porcupine.org/pub/security/tcp_wrappers_7.6.tar.gz
 cd tcp_wrappers_7.6 
ではMakefileを編集します。
 REAL_DAEMON_DIR = /usr/sbin <-/etc/inetd.confを開いてtelnetのserver_pathのディレクトリ
 FACILITY = LOG_DAEMON <-LOG_MAILから変更
 DOT= -DAPPEND_DOT <-コメントを取る。Reduce DNS load DNS負荷軽減
 AUTH = -DALWAYS_RFC931 <-コメントを取る。Always attempt remote username lookups
 ACCESS = -DHOSTS_ACCESS <- Turning off access control
では編集後、
 make linux
エラーが...
 percent_m.c:17: conflicting types for `sys_errlist'
ではMakefileの148行目の
 NETGROUP= TLI= EXTRA_CFLAGS="-DBROKEN_SO_LINGER" all
を
 NETGROUP= TLI= EXTRA_CFLAGS="-DBROKEN_SO_LINGER -DSYS_ERRLIST_DEFINED" all
に修正して、再度make linux。ではインストール
 cp tcpd tcpdchk tcpdmatch safe_finger try-from /usr/sbin/
 cp *.3 /usr/share/man/man3
 cp *.5 /usr/share/man/man5
 cp *.8 /usr/share/man/man8
 cp tcpd.h /usr/include/
 cp libwrap.a /usr/lib/
 cd /usr/sbin
 chown root tcpd tcpdchk tcpdmatch safe_finger try-from
 chgrp root tcpd tcpdchk tcpdmatch safe_finger try-from
 chmod 700 tcpd
 chmod 711 tcpdchk tcpdmatch safe_finger try-from
ではOpenSSHのインストール
 tar xzvf openssh-3.9p1.tar.gz
 cd openssh-3.9p1
README.privsepより
 mkdir /var/empty
 chown root:sys /var/empty
 chmod 755 /var/empty
 groupadd sshd
 useradd -g sshd -c 'sshd privsep' -d /var/empty -s /bin/false sshd
これをしておかないと インストール時にPrivilege separation user sshd does not exisとエラーがでます。
 ./configure --with-pam --with-tcp-wrappers --with-ipv4-default
うっ..またエラーが...
 PAM headers not found
どうもpam-develがないからだそうです。ではrpmかapt-get,dselect(libpam0g-dev)でインストールしておきます。なぜかapt-getでインストールできなったので、dselectでインストールしました。
 make
 make install

** 環境設定
OpenSSHがインストールされていたので、/etc/ssh/sshd_configを編集します。/usr/local/etcにある場合もあります。ssh_configというファイルがあるときもあるので、間違えないように。
-Protocol 2,1  ssh2を優先します。ssh2のみの場合はProtocol 2にします。
-PasswordAuthentication no パスワード認証を無効
-PermitEmptyPasswords no パスワードなしでのログインを禁止
-PermitRootLogin no rootでのログインを禁止
-AuthorizedKeysFile     .ssh/authorized_keys 公開鍵のファイル名
***SSH1
SSH1は公開鍵暗号にRSAを使用しています。ユーザ用のキーを作る場合はそのユーザになって
 ssh-keygen -t rsa1
とすると、その指定された中に(デフォルトは /home/user名/.ssh/)に identityとidentity.pubの2つができています。このうちidentity.pubが公開鍵でidentityが秘密鍵になります。
 cat identity.pub >> authorized_keys
 rm identity.pub
 chmod 600 authorized_keys
としておきます。これで公開鍵ができあがりです。ここでできたidentityをログイン時に使用してください。
***SSH2
SSH2は公開鍵暗号にDSAを使用しています。そのユーザになって
 ssh-keygen -b 1024 -t dsa
すると
 Enter file in which to save the key (/home/hoge/.ssh/id_dsa): <-リターン
 Enter passphrase (empty for no passphrase): <-パスワード
 Enter same passphrase again: <-もう一度パスワード
 Your identification has been saved in /home/hoge/.ssh/id_dsa.
 Your public key has been saved in /home/hoge/.ssh/id_dsa.pub.
と表示されます。
 cd .ssh
としますと、id_dsaとid_dsa.pubの2つのファイルができています。
 cat id_dsa.pub >> authorized_keys
 rm id_dsa.pub
 chmod 600 authorized_keys
ここでできたid_dsaをログイン時に使用してください。
** TIPS
***Authentication refused: bad ownership or modes for directory /home/hogehoge
/home/hogehogeのアクセス権を確認しましょう。700とか755にしてみてください。
***接続の確認
/var/log/secure

** リンク
http://www.net-newbie.com/putty.html~
http://www.atmarkit.co.jp/flinux/rensai/linuxtips/432makesshkey.html~
http://home.opaopa.org/solaris9/ssh.html~
http://www.unixuser.org/~euske/doc/openssh/jman/ssh-keygen.html~
http://www.ipa.go.jp/security/awareness/administrator/secure-web/chap4/4_openssh.html~
http://lightly.plala.jp/memo/install.html#tcp_wrappers~
http://www.edu.ics.saitama-u.ac.jp/~nagumo/tcpwrapper/~
http://www.ryouto.jp/linux/linux_45.html~
http://www.tcn.zaq.ne.jp/gara_k/pc_unix/pc_unix_019.htm~
** 参考書籍

トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS