Skip to content

Instantly share code, notes, and snippets.

@RedenticDev
Last active March 14, 2021 14:02
Show Gist options
  • Save RedenticDev/560ba1c117fa40a18e1b7db44d027380 to your computer and use it in GitHub Desktop.
Save RedenticDev/560ba1c117fa40a18e1b7db44d027380 to your computer and use it in GitHub Desktop.
Connect to your remote host without entering password

These instructions are made to allow you to connect your remote device through ssh without password. Tested on macOS and Ubuntu.

Disclaimer: despite this method is well-known and quite secure, you should not use this from untrusted devices. I'm not responsible if something goes wrong with this.

Step 1: add your remote device as a known/trusted host

$USER is the remote user and $HOST the remote host (e.g.: ssh $USER@$HOST where $USER=root and $HOST=iPhone will connect to the remote host iPhone with the user root.

ssh-keygen -t rsa # generate a pair of public/private keys encrypted with RSA
ssh $USER@$HOST "mkdir .ssh" # creates a .ssh folder at the user directory of the remote machine
cat .ssh/id_rsa.pub | ssh $USER@$HOST 'cat >> .ssh/authorized_keys' # adds your public key in the authorized keys of the remote machine

Note: remember the passphrase you set during the first command!

Step 2: remove needing of passphrase

With the previous step, trying to connect to your remote host will ask you your passphrase instead of the remote machine's password. To avoid this and remove any prompted password, type:

macOS

eval $(ssh-agent) # check if ssh agent is running
ssh-add .ssh/id_rsa # add your private key to the agent (some keys are 'id_rsa_key' instead of just simply 'id_rsa', adapt it to your configuration)
ssh-add -l # optional, list if the previous command has been successful

Run this each time you add a new device thanks to the step 1.

Linux

Under Linux distors, the eval command and the first ssh-add command have to be ran each time you login to your terminal. To avoid that, run:

sudo apt-get install keychain # install keychain to manage ssh
echo 'eval $(keychain -q --eval id_rsa)' >> ~/.bashrc # add this command at the end of your .bashrc, which is run each time you open a new terminal instance

Then relaunch your terminal.

That's it!

Now you can connect your remote host securely, avoiding the need to type the password everytime, specifically when you do it often.
I personnally use it to connect to all my test iPhone when I run make install with Theos. You need to install the package OpenSSH if you want to do it too for your iPhone. The default password for it is alpine, but you can (must) change it by going to root with su, and typing passwd.
In case of problems or typos, reach me out on my Twitter.

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