After bearing my soul regarding my battles with SSH keys, Bitbucket and GIT, I was pleasantly surprised to receive a comment on the post. My initial pleasure was in realising that someone actually read the thing (presumably to the end in order to reach the comments section), so I was overjoyed when I realised I wasn’t being sold viagra, and ecstatic when I realised that the post contained a solution to my problems with SSH keys needing to be re-added after every system restart.
The comment (left by the incredibly helpful sjstreeting), for anyone too lazy to go and take a look at the original post was:
About the issue when restarting your Mac, this definitely sucks and was a change in El Capitan. You now need to run `ssh-add -A` at least once after you log in; personally I’ve put this in a script which I added to my Login Items in System Preferences > Users & Groups. HTH
In order to generate a script that could be run from the Login Items in my system preferences, I used the inbuilt Automator app, which is possibly my new favourite thing on my MAC. You’ll find it hidden away inside the mysterious “other” section of your MAC’s launchpad alongside various other apps that someone with my limited knowledge probably shouldn’t play with (and that includes the chess app).
Once you’ve braved clicking on what looks like a robot wielding a bazooka, click to open a new document, and then choose “Application” as the “type” for your document.
There should be a “Library” item open in the left side bar, if not, click on the “Library” link to open it.
Select “Utilities”, and double click ” Run shell script” from the list of Utilities.
Copy-and-paste the following into the textarea:
cd ~/.ssh ssh-add -A
Test the script by pressing the “run” button (click ok on the message regarding application not receiving input). You should receive two shiny green ticks for your efforts in the log for “Run Shell Script completed”, and “Workflow completed”.
Save it (file/save). I saved to
Applications/add-ssh-keys.app but I’m sure you can come up with something far more exciting.
Close the automator app down, we don’t need it anymore, and frankly, that heavily armed robot is scaring me.
Now go to System Preferences/Users & Groups on your MAC. Select your profile and select “Login items”.
Click the plus sign to add your app to the “These items will open automatically when you log in” box.
Locate your app and select it.
Close the window.
Restart your MAC (or wait until the next time you have too), and marvel at the fact you can still use your Bitbucket SSH key without having to swear at SourceTree for flashing up red letters at you when you try and push to a repo. For bonus homework, write a script that does something offensive on start-up, and see if you can get it to run on a work colleague or family member’s machine on every load.