SSH Agent Forwarding Mac / Windows

When I was starting in development workflow (github, terminal deployment, database migration, etc) my main headache was getting SSH Agent Forwarding  to work for me.  For Mac is actually pretty easy, so lets start with that:

First if you have multiple keys on your system the fist thing to do is add the keys you want the agent to use:

ssh-add *address_to_your_key*

Where *address_to_your_key* is the path to where your private key is stored.

Then let just make sure we enable the agent, we need to modify your ssh config you can do that by typing

vi ~/.ssh/config

Then just add the following to the file if you want to enable ssh key forwarding to all servers, this means your key will be send to every server you connect and I don’t recommend it, but is a dirty way to save time: 

Host *
ForwardAgent yes

The best way to do it  is adding a line to that same file for each domain or IP

Host 192.158.22.12
ForwardAgent yes

Just take into consideration you need to add the domain and the IP, because if you only add the IP and then connect using the domain the key won’t be sent, same thing on the opposite case

Host mysshserver.dev
ForwardAgent yes

You can also use a lot more configuration on each snippet

Host ssh1
     HostName mysshserver.dev
     User nixcraft
     Port 4242
     IdentityFile *any_key_you_want*
     ForwardAgent yes

This will allow you to connect easily to that server using

ssh ssh1

But also setting the user if it is different than your local user, setting a special key just for that server and changing the port if required.

 

Get your Scotchbox on!

Vagrant (boxed enviroments) for me is maybe the best thing to happen to dev tools in a long time. Being able to easily distribute testing env to all developers, and keeping PHP projects in separate boxes and being able to bring them up easily, is glory for somebody who used to run up to 100+ projects in a single LAMP installation in Windows.

Scotchbox for me is one of the greatest (https://box.scotch.io/), you can also get a variety of flavors for different developments:

https://scotch.io/