I recently came into contact with an SSH server (on my iPhone) and I’m enjoying this new functionality OpenSSH brings to my iPhone. In fact, I’m thinking of installing an SSH server on my Ubuntu fileserver.

Here are 4.5 basic commands you should know in order to effectively use SSH no matter what server you’re logging into.

 

Tip 1: Logging In

After you make sure that your server is running (if you’re doing this on the iPhone, it starts running as soon as it’s installed), open up a terminal window. On a Mac, type command + space and type terminal, on Linux/Gnome goto Applications -> Accesories -> Terminal. Find the IP of your SSH server, and in the terminal window, type the following:

SSH root@192.168.x.x

in the form of

SSH [username]@[ip address]

For the iPhone, your username will be “root”. You will need to be logged in for the rest of the steps in this guide.

Please note that if it’s your first time connecting to the server, it will take some time to generate RSA keys so your computer can connect to the server securely. Afterwards, it may ask you if you wish to continue connecting. Type “yes” and press the enter key.

razorrifhs-computer:~ razorrifh$ SSH root@192.168.2.6

The authenticity of host ‘192.168.x.x (192.168.x.x)’ can’t be established.

RSA key fingerprint is 60:cf:e0:13:02:4d:3c:a2:91:9b:d8:bf:c5:57:49:fc.

Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.2.6' (RSA) to the list of known hosts.

 

It will then ask you for your password. After entering it successfully you’ll be remotely logged into the remote system.

 

Tip 2: Changing Your Password

After logging in for the first time, you’ll probably want to change the password. There are some situations where this may not be true, but it’s good to know either way!

After being logged in to the SSH server, type the command:

passwd

You’ll then get the following prompts:

Changing password for root.
New password:

Enter your new password both times when it asks you and it’ll change your password immediately.

 

Tip 3: How to Use Basic File Commands

Once you’re logged in, you might want to poke around and look at the files on your phone/server. To do this, you’ll need to know some basic commands. The four commands you’ll most likely need to know are:

ls - Lists the files in the current directory. Usage: ls

cd - Changes the Directory. Usage: cd /Applications

mkdir - Makes a Directory in the current or specified directory. Usage: mkdir /var/mobile/Documents 
rm - Removes a directory. Usage: rm /var/mobile/Documents

 

Tip 4: How to End Your SSH Session

There’s actually several ways to end your SSH session. Try the following commands:

exit
logout

or you can force the connection closed by holding the CTRL button and pressing “D”.

There’s also another method to get the SSH client to disconnect rather than disconnecting from the server. This method uses an SSH command line escape sequence. Hit enter a few times to make sure you’re starting on a new line, and type:

~. (a tilde and a period]

This will end the SSH connection from the client side.

 

Tip 4.5: Fix a Possible SSH Error

I had to restore my iPhone (more than once!) and in the process the keys that were generated the first time I logged in after I restored. SSH thought a man in the middle attack was happening and threw a huge error. I simply had to regenerate the keys and it didn’t have a problem connecting after that.

If you get this error:

razorrifhs-computer:~ razorrifh$ SSH root@192.168.x.x

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    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 the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
60:cf:e0:13:02:4d:3c:a2:91:9b:d8:bf:c5:57:49:fc.
Please contact your system administrator.
Add correct host key in /Users/razorrifh/.ssh/known_hosts to get rid of this message.
Offending key in /Users/razorrifh/.ssh/known_hosts:1
RSA host key for 192.168.x.x has changed and you have requested strict checking.
Host key verification failed.

All you have to do to regenerate the key is use the following command:

ssh-keygen -R [ip address]

You’ll see the following prompts knowing the command worked correctly.

razorrifhs-computer:~ razorrifh$ ssh-keygen -R 192.168.x.x
/Users/razorrifh/.ssh/known_hosts updated.
Original contents retained as /Users/razorrifh/.ssh/known_hosts.old