How to SSH to an iPhone or iPad
You may know already that iOS has the same underlying unix architecture as Mac OS X, and because of this you can SSH into an iPhone or iPad just like you would connect to any other Mac or unix based machine.
As it turns out for us nerdier users, this ability is disabled without a jailbreak, so in order to SSH into your iOS device you will need to jailbreak first. How to do this varies on what version of iOS your hardware is using, but you can find our jailbreak info here depending on your specific iOS version and device model of iPhone or iPad.
To clarify, this is a guide on how to setup the ability to SSH into your iPhone or iPad from another machine, if you are just looking for an SSH client for the iPhone or iPad, Prompt on the iOS App Store is by far the best, and costs $15 or so.
How to Setup SSH and then Connect with SSH to an iPhone or iPad
As previously mentioned, the first thing you need to do is jailbreak, that is out of the scope of this article but it’s easy to do. After your iPhone, iPad, or iPod touch is jailbroken, proceed with the following:
Step 1) From the iOS Device:
- Launch Cydia and search for and install OpenSSH (it’s in the networking section on Cydia) – you won’t see anything on your Springboard because this runs in the background
- After OpenSSH is downloaded and installed, tap onto “Settings” and then onto “Wi-Fi”
- Tap on the arrow next to the WiFi router you are connected to, this will bring up the wireless network settings
- Make note of the IP Address visible on the first screen, as an example we’ll say it’s 192.168.1.103
Step 2) SSH from your Mac or Windows PC:
- Launch the Terminal in Mac OS X, or PuTTY for Windows users
- Type the following at the command line:
- Wait a minute or two while the SSH encryption keys are generated, accept them when (if) asked – this delay only occurs the first time you ssh from a computer to the iOS device
- When asked for a password, use “alpine” but without the quotes, this is the default password for all iOS devices
ssh root@192.168.1.103
Remember to use the IP address you found in the prior step on your iPhone
You can learn more about using the Mac SSH client here if interested.
Step 3) Change the Default iOS Passwords:
You will now be connected to your iPhone or iPad via SSH. The first thing you’re going to want to do is change the default passwords, otherwise anyone on the network could theoretically connect to your iPhone, iPad, or iPod touch. This is just a matter of typing the following command:
passwd
Provide a new password and then confirm it when asked.
Now you’ll want to change the ‘mobile’ ID password to be safe, this is basically the same procedure:
passwd mobile
Enter a new password and confirm it.
The video below walks through the process of changing the root passwords. This is very easy and only takes a moment.
If you plan on connecting to your iOS device frequently, you may want to set a manual DHCP IP address so that it doesn’t change on you, and then setup an SSH alias so you don’t have to type the entire connection string again.
SSH into your iPhone from the iPhone (or iPad to itself, etc) ie: Connect to localhost
:
For connecting to localhost from your iOS device, you just need to have an SSH or Terminal client on the iPhone itself. Again, I’ll suggest Prompt from iOS App Store, but there are other options out there.
SFTP to the iPhone or iPad
:
Transferring files to the iPhone or iPad is just a matter of using SFTP after OpenSSH has been installed and is running. You’ll use the same IP address, login, and password as connecting with SSH, just from an ftp client instead of the Terminal. A few good free FTP clients are CyberDuck for Mac, or Filezilla for Mac, Windows, and Linux.
Misc on SSH
This obviously applies to iOS and the iPhone and iPad, but the Mac has a native SSH server available to enable as well and it’s a lot easier to toggle on through a settings panel, or you can enable the SSH server through the Mac command line if preferred, either is quite a bit simpler compared to using a jailbreak like what is necessary in iOS.
If you have any additional insight or tips about using SSH on iOS, share in the comments below!
What should I do if I don’t have internet,but I have data
[…] the Terminal or your preferred SSH client, find the iOS IP address, and connect to the iPhone using SSH […]
ssh root@192.168.1.*** timed out?????
alpine password will not work for me…..
ssh localhost
done
smart ! but doesn’t work at all