iPhone 3G 3.1.2 Open SSH 公開鍵認証

iPhoneのOpenSSHを安全に使う設定(jailbreak後)を見てもよく分からなかったので

クライアント(PC,Mac,Linuxなど)側から

 $ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/xxx/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/xxx/.ssh/id_rsa.
Your public key has been saved in /Users/xxx/.ssh/id_rsa.pub.
The key fingerprint is:
2b:b4:84:10:57:79:36:00:73:c8:e7:7f:c0:db:da:fb xxx@xxxxx.toyholic.com
The key's randomart image is:
+--[ RSA 2048]----+
|  ..+++o         |
|   oooo +        |
|  .  o + .       |
|   . .. o        |
|    . o.S+       |
|     o .o.o      |
|      o .+       |
|       .. .      |
|          .oE    |
+-----------------+
$ cd .ssh/
$ pwd
/Users/xxx/.ssh
$ ls
id_rsa		id_rsa.pub	   known_hosts

公開鍵をiPhoneに転送する。パスワード認証を切っていないのでパスワードを入れて

$ scp id_rsa.pub mobile@xxxxx.toyholic.com:/var/mobile/.ssh
mobile@xxxxx.toyholic.com's password:
id_rsa.pub                                    100%  404     0.4KB/s   00:00

sshサーバー(iPhone)側に移動して

$ cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

公開鍵で入れるかな。

$ ssh -v mobile@xxxxx.toyholic.com
OpenSSH_5.2p1, OpenSSL 0.9.8l 5 Nov 2009
debug1: Reading configuration data /etc/ssh_config
debug1: Connecting to xxxxx.toyholic.com [192.168.24.198] port 22.
debug1: Connection established.
debug1: identity file /Users/xxx/.ssh/identity type -1
debug1: identity file /Users/xxx/.ssh/id_rsa type 1
debug1: identity file /Users/xxx/.ssh/id_dsa type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.2
debug1: match: OpenSSH_5.2 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.2
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP debug1: SSH2_MSG_KEX_DH_GEX_INIT sent debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY debug1: Host 'xxxxx.toyholic.com' is known and matches the RSA host key. debug1: Found key in /Users/xxx/.ssh/known_hosts:1 debug1: ssh_rsa_verify: signature correct debug1: SSH2_MSG_NEWKEYS sent debug1: expecting SSH2_MSG_NEWKEYS debug1: SSH2_MSG_NEWKEYS received debug1: SSH2_MSG_SERVICE_REQUEST sent debug1: SSH2_MSG_SERVICE_ACCEPT received debug1: Authentications that can continue: publickey,password,keyboard-interactive debug1: Next authentication method: publickey debug1: Trying private key: /Users/xxx/.ssh/identity debug1: Offering public key: /Users/xxx/.ssh/id_rsa debug1: Server accepts key: pkalg ssh-rsa blen 277 debug1: read PEM private key done: type RSA debug1: Authentication succeeded (publickey). debug1: channel 0: new [client-session] debug1: Requesting no-more-sessions@openssh.com debug1: Entering interactive session. green:.ssh xxx$ ssh -v mobile@xxxxx.toyholic.com OpenSSH_5.2p1, OpenSSL 0.9.8l 5 Nov 2009 debug1: Reading configuration data /etc/ssh_config debug1: Connecting to xxxxx.toyholic.com [192.168.24.198] port 22. debug1: Connection established. debug1: identity file /Users/xxx/.ssh/identity type -1 debug1: identity file /Users/xxx/.ssh/id_rsa type 1 debug1: identity file /Users/xxx/.ssh/id_dsa type -1 debug1: Remote protocol version 2.0, remote software version OpenSSH_5.2 debug1: match: OpenSSH_5.2 pat OpenSSH* debug1: Enabling compatibility mode for protocol 2.0 debug1: Local version string SSH-2.0-OpenSSH_5.2 debug1: SSH2_MSG_KEXINIT sent debug1: SSH2_MSG_KEXINIT received debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client-&server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host 'xxxxx.toyholic.com' is known and matches the RSA host key.
debug1: Found key in /Users/xxx/.ssh/known_hosts:1
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Next authentication method: publickey
debug1: Trying private key: /Users/xxx/.ssh/identity
debug1: Offering public key: /Users/xxx/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 277
debug1: read PEM private key done: type RSA
debug1: Authentication succeeded (publickey).
debug1: channel 0: new [client-session]
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
mobile$ chmod 700 .ssh
mobile$ chmod 600 .ssh/authorized_keys

セキュリティ的にmobileってユーザー危ないけど削除したら大変だろうな。
chmod -R 755 /private/var/でCydiaも何もかも起動しなくなったんだな。う〜ん

コメントする