鍵の作成やsshdの設定など
一般ユーザ追加
サーバにログインし、ユーザを追加
$ ssh root@192.168.0.101 # useradd moogme -d /home/moogme ユーザ作成 # visudo sudoersに追加 moogme ALL=(ALL) ALL グループ単位ではなくて、個人単位で全部与えてみた。 # passwd moogme パスワード変更 # exit
mac側で鍵作成
$ ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/Users/moogme/.ssh/id_rsa): エンター Created directory '/Users/moogme/.ssh'. Enter passphrase (empty for no passphrase):パスワード Enter same passphrase again: パスワード Your identification has been saved in /Users/moogme/.ssh/id_rsa. Your public key has been saved in /Users/moogme/.ssh/id_rsa.pub. The key fingerprint is: f4:06:90:a8:d3:69:10:c3:24:6c:2f:96:46:32:e5:68 moogme@MacBook.local The key's randomart image is: +--[ RSA 2048]----+ |o+=. ... | |oBo.. .. | |=E++ . o | |.=o.+ . o | |o .o S o | | . | | | | | | | +-----------------+ $ cd $HOME/.ssh $ mv id_rsa.pub authorized_keys $ chmod 600 authorized_keys
公開鍵 : authorized_keys
秘密鍵 : id_rsa
$ ssh moogme@192.168.0.101 mkdir /home/moogme/.ssh The authenticity of host '192.168.0.101 (192.168.0.101)' can't be established. RSA key fingerprint is f3:08:fe:7c:51:05:69:93:45:13:a4:06:77:e9:c4:a4. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '192.168.0.101' (RSA) to the list of known hosts. moogme@192.168.0.101's password: $ scp authorized_keys 192.168.0.101:/home/moogme/.ssh
反対に、サーバで作成して、macに持ってきてもいいかも。
$ ssh moogme@192.168.0.101 マックからサーバへログイン
さっき、mac側から作った .ssh ディレクトリと authorized_keys のパーミッション変更
$ chmod 700 $HOME/.ssh $ chmod 600 $HOME/.ssh/authorized_keys
sshd設定
$ sudo vim /etc/ssh/sshd_config Protocol 2 SSH2だけを有効にする PermitRootLogin no rootでのログインを禁止 PermitEmptyPasswords no 空パスワードでのログインを禁止 PasswordAuthentication no 鍵認証以外のログインを禁止 PermitEmptyPasswords no とかぶってる予感。 X11Forwarding no X11転送を禁止 LogLevel INFO ログレベル $ sudo /etc/init.d/sshd restart sshd再起動 sshd を停止中: [ OK ] sshd を起動中: [ OK ]
ここで、一度サーバからログアウトし、mac側から鍵でログインできるかテスト。
しかし、何か間違っていると、ログインできなくなってしまう。 その場合はサーバに直接キーボードを繋いで修正するしかない。。
$ exit サーバからログアウト $ ssh moogme@192.168.0.101 再度ログイン。もう、鍵認証しか受け付けていないはず。 [moogme@localhost ~]$
成功した。
参考にしました
http://www.atmarkit.co.jp/fsecurity/rensai/unix_sec05/unix_sec01.html
http://www14.plala.or.jp/campus-note/vine_linux/server_ssh/sshd_config.html