CentOSで公開鍵認証をする
まずクライアント(Mac)で公開鍵を作成します。
mac$ ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/Users/anmino/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /Users/anmino/.ssh/id_rsa. Your public key has been saved in /Users/anmino/.ssh/id_rsa.pub. The key fingerprint is: 18:3d:8d:1c:e3:b4:d1:ec:fe:66:92:e8:46:ee:d3:b6 anmino@anmino-no-MacBook-Pro.local The key's randomart image is: +--[ RSA 2048]----+ | =o | | = Bo | | . B.. | | o .. | | . S. | | . . | | o o o | | = = + | | +ooE= | +-----------------+ mac$ ls .ssh id_rsa id_rsa.pub
macで作成した公開鍵をCentOSで作ったユーザーのホームディレクトリにコピーする
mac$ scp ~/.ssh/id_rsa.pub anmino@192.168.54.10: anmino@192.168.54.10's password: id_rsa.pub 100% 423 0.4KB/s 00:00
CentOSで公開鍵を登録する
$ ls id_rsa.pub $ mkdir .ssh $ chmod 700 .ssh $ mv id_rsa.pub .ssh/authorized_keys $ chmod 600 .ssh/authorized_keys
SSHの設定
$sudo vi /etc/ssh/sshd_config Port 10022 # ポート番号の変更 PermitRootLogin no # rootログイン禁止 PasswordAuthentication no # パスワードでのログイン禁止 AllowUsers anmino # SSHを許可するユーザを設定
SSHサーバーを再起動
$ sudo /sbin/service sshd restart Stopping sshd: [ OK ] Starting sshd: [ OK ]
mac$ ssh anmino@192.168.54.10 Identity added: /Users/anmino/.ssh/id_rsa (/Users/anmino/.ssh/id_rsa) Last login: Wed Apr 20 20:12:14 2011 from 192.168.54.1
sudo実行時にパスが通ってないので設定します。
mac$ vi .bash_profile PATH=$PATH:/sbin PATH=$PATH:/usr/sbin PATH=$PATH:/usr/local/sbin $ source ~/.bash_profile