2. Setup Public Key Authentication
Public Key Authentication is a method of allowing a specific user on a specific computer to access another computer via SSH without having to type a password to authenticate the session. In this instance, we'll be setting things up where the root user on your mac is trusted to access the root user on your iPhone via SSH. This is required in order for the script on the next page to function properly.
Step 1: Generate SSH keys
Open terminal. Do:
sudo ssh-keygen
After typing your admin password (because you used sudo) you will be asked a name for the key. Press return without entering a name. Next you will be asked twice for a passphrase. Leave this blank also, simply pressing return both times.
Your computer should state it has successfully created your keys, storing them in /var/root/.ssh/ . These two files are named "id_rsa" and "id_rsa.pub" and now reside in that location.
Step 2: Copy public key to iPhone
Public Key Auth requires that both private (id_rsa) and public (id_rsa.pub) keys reside on the client computer (your mac), and that only the public key is placed onto the host (iPhone). ssh-keygen already placed both keys in the proper location on your mac, but we will need to move the public key to iPhone.
You'll need first to create the directory this file is going into. To do this, SSH into your iphone and run:
mkdir /var/root/.ssh/
Then exit the SSH session, and in the terminal locally on your mac, do:
sudo scp /var/root/.ssh/id_rsa.pub root@YOUR_IPHONES_IP_ADDRESS:/var/root/.ssh/
Beware you will be asked for your iPhone's root password this time, not your mac's root password. This will copy the public key onto your iPhone. You must be set up to SSH and know your iPhone's IP address in order for this command to work.
Step 3: Re-Name and CHMOD the Public Key
SSH into your iPhone.
ssh root@YOUR_IPHONES_IP_ADDRESS
And run the following commands, one after the other, pressing return after entering each:
mv /var/root/.ssh/id_rsa.pub /var/root/.ssh/authorized_keys2
chmod 755 /var/root
chmod 700 /var/root/.ssh
chmod 644 /var/root/.ssh/authorized_keys2
Then close the SSH connection:
exit
Step 4: Test Public Key Authentication
Now we need to test Public Key Authentication. If the above was successful, establishing a SSH connection to iPhone as root (that is, using sudo) will not require the iPhone's root password to be entered. (Though yours may have to be entered to run sudo. This can be a confusing difference.)
Attempt to SSH into your iPhone as root on your local computer. DON'T miss the sudo here:
sudo ssh root@YOUR_IPHONES_IP_ADDRESS
This is likely the first time you're doing this, so your computer may ask if you wish for this to be a trusted host. Answer YES to the yes/no question. At this point you should now be SSH'd into your iPhone without having had to enter it's root password. To verify this, exit and log back in again using sudo ssh. This time it should be smooth and require no input to log into the iPhone. If this is the case, congrats. You've set up Public Key Auth and are ready for the next step.