Wednesday, August 26, 2015

SSH using your Mac Terminal

As a windows user, I'm used to using PPK keys and putty to SSH. But with mac osx, I don't have to download any software and just SSH in my terminal.

With mac, you'll be needing a .pub file. I tried converting my PPK in windows to mac but so far I have not found a good way to convert it, I'm having problem with passphrase. For some reason it's not accepting the right passphrase.

I found a good blog  that explains how to create key and clone your git repository: using-git-and-github-on-os-x and a blog post in atlassian ssh config

If you simply one to create key, then you can just follow Step 1 and 2:
Open your terminal and...
1) Go to .ssh folder ( usually located in ~/.ssh )
2) ssh-keygen

Now for you to be able to successfully SSH, you need to know 2 more commands before starting your ssh...

SSH CommandPurpose
ssh-keygenCreates key pairs.
ssh-agentAgent for providing keys to remote servers. The agent holds loaded keys in memory.
ssh-addLoads a private key into the agent.

You need to make sure that ssh-agent is running because it's the one holding the keys that you're going to load to the remote server you're going to connect to.

To run it, just simply type: eval ssh-agent
in your terminal.

Then you need to load the keys you have in your .ssh folder: ssh-add
If you want to specifically add a key, you can add the location of the key after ssh-add <key_location>

To verify if it's all loaded, just do: ssh-add -l

Now, you can finally ssh you your remote server: ssh <remote server ipaddress or domain>

Next time you need to connect, you can just run the agent together with your ssh command by doing this: ssh -A <remote server address> or if they key can't be found for some reason you can try calling the key too ssh -A -i <yourkey_loc> <remote server address>

I hope this helps. :)