Skip to content

Instantly share code, notes, and snippets.

@DomiR
Last active October 22, 2021 00:05
Show Gist options
  • Save DomiR/8870918 to your computer and use it in GitHub Desktop.
Save DomiR/8870918 to your computer and use it in GitHub Desktop.
Iphone passwordless ssh

Passwordless SSH

If you have no own key in ~/.ssh/ calld id_rsa.pub then create one:

ssh-keygen -t rsa

Copy the public file to the iphone

scp id_rsa.pub root@IPHONIP

Login to iphone

ssh root@IPHONEIP

Copy key to authorized_keys

mkdir .ssh
cat id_rsa.pub >> .ssh/authorized_keys
chmod 644 .ssh/authorized_keys
chmod 700 .ssh

Edit /etc/ssh/sshd_config

nano /etc/ssh/sshd_config

// - uncomment this - // 
#RSAAuthentication yes
#PubkeyAuthentication yes
#AuthorizedKeysFile .ssh/authorized_keys

// -       to       - // 
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys

Restart sshd

launchctl stop com.openssh.sshd
launchctl start com.openssh.sshd

Everthing in one run

APPLEIP="<IP>"
cat ~/.ssh/id_rsa.pub | ssh root@$APPLEIP '(
	cat > /var/root/tmp.pubkey;
	mkdir -p /var/mobile/.ssh;
	touch /var/mobile/.ssh/authorized_keys;
	cat tmp.pubkey >> /var/mobile/.ssh/authorized_key;
	chmod 644 /var/mobile/.ssh/authorized_keys;
	chmod 700 /var/mobile/.ssh;
	mkdir -p /var/root/.ssh;
	touch /var/root/.ssh/authorized_keys;
	cat tmp.pubkey >> /var/root/.ssh/authorized_keys;
	chmod 644 /var/root/.ssh/authorized_keys;
	chmod 700 /var/root/.ssh;
	rm /var/root/tmp.pubkey;
	echo "RSAAuthentication yes" >> /etc/ssh/sshd_config;
	echo "PubkeyAuthentication yes" >> /etc/ssh/sshd_config;
	echo "AuthorizedKeysFile .ssh/authorized_keys" >> /etc/ssh/sshd_config;
	launchctl stop com.openssh.sshd;
	launchctl start com.openssh.sshd;
	)'

Backing Up Your Packages

dpkg –get-selections> installed-apps.txt

Restore

passwd
login mobile

passwd
dpkg --install bigbosshackertools

# Set debs 
dpkg –-set-selections< installed-apps.txt
apt-get -u dselect-upgrade
@mohwie
Copy link

mohwie commented Apr 28, 2018

Make it file

@favna
Copy link

favna commented Jul 7, 2018

Few adjustments I made that I think are better for iOS 11

Copy key to authorized_keys

cat id_rsa.pub >> /private/etc/ssh/authorized_keys
chmod 644 /private/etc/ssh/authorized_keys

Edit /private/etc/ssh/sshd_config

nano /private/etc/ssh/sshd_config
// - from this - // 
#PubkeyAuthentication yes
#AuthorizedKeysFile .ssh/authorized_keys

// - to this    - // 
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile /private/etc/ssh/authorized_keys
// - and a bit further down you will find - //
# To disable tunneled clear text passwords, change to no here!
# PasswordAuthentication yes
# PermitEmptyPasswords no

// - edit that to this - //
# To disable tunneled clear text passwords, change to no here!
PasswordAuthentication no
PermitEmptyPasswords no

Reasons:

  • RSAAuthentication is not in the file by default on Electra jailbreak, it has to be added entirely
  • putting the auth keys along with the config and all other SSH related settings is where it should be, no reason to create a new folder
  • if anything it would have to be /.ssh/authorized_keys otherwise it doesn't know to look in / (root)
  • no more need to edit the folder's RWE permissions since the folder already exists

@chashmeetsingh
Copy link

Still have to enter password to move forward. @favna

@supermamon
Copy link

here’s what I did on iOS 11. I already have my ssh keys

ssh-copy-id -i <path to pub key> root@iphone-ip-address

done.
I didn’t need to add anything on sshd_config. I guess those are enabled by default.

@AnthoPakPak
Copy link

AnthoPakPak commented May 2, 2019

@supermamon Worked with this single command, thanks a lot for sharing!
For the record, the command would be something like that ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.0.5

@SwiftWinds
Copy link

SwiftWinds commented Jan 3, 2020

@supermamon Confirmed working on iOS 12.4. Thanks for the hasty treat! ❤️😋

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment