Smoothly SSH into different devices w/o being interrupted


#1

In the Theos part of the book, I have introduced ssh-keygen to SSH into your jailbroken iOS w/o entering password. But for those like me who have several jailbroken devices to debug, when we switch device and want to SSH again, we meet this:

FunMaker-AMBP:~ snakeninny$ ssh root@localhost -p 2222
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
SHA256:HRbCnZTgABzK0lV/Djt/JihgiuaTTJYSjOSu9pQ1vgk.
Please contact your system administrator.
Add correct host key in /Users/snakeninny/.ssh/known_hosts to get rid of this message.
Offending RSA key in /Users/snakeninny/.ssh/known_hosts:2
RSA host key for [localhost]:2222 has changed and you have requested strict checking.
Host key verification failed.

What I always do, is deleting line 2 of known_hosts and SSH again:

FunMaker-AMBP:~ snakeninny$ vi /Users/snakeninny/.ssh/known_hosts
FunMaker-AMBP:~ snakeninny$ # Line 2 of known_hosts is deleted here
FunMaker-AMBP:~ snakeninny$ ssh root@localhost -p 2222
The authenticity of host '[localhost]:2222 ([127.0.0.1]:2222)' can't be established.
RSA key fingerprint is SHA256:HRbCnZTgABzK0lV/Djt/JihgiuaTTJYSjOSu9pQ1vgk.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[localhost]:2222' (RSA) to the list of known hosts.

Which takes much time and is not smooth and elegant enough. A better solution for people like me, would be a simple bash script:

#!/bin/sh
sed -i '' '/localhost/d' ~/.ssh/known_hosts # Delete the line containing 'localhost'
ssh -o "StrictHostKeyChecking no" root@localhost -p 2222 # SSH w/o being prompted
exit 0

Save this script as a file named “iSSH” and run chmod +x /path/to/iSSH to grant it execute permission, then put it to wherever you prefer (I suggest this place). Next time you want to SSH into another device, simply run iSSH and you’ll get there.

Happy hacking!


#2
ssh -i ~/.ssh/id_rsa -o LogLevel=ERROR -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p $SSH_PORT root@$host $*