This is my recipe for using git via ssh in the terminal panel of Atom for Windows.
For my own git projects on GitHub and work projects on VSTS, I prefer to use ssh with command line over a GUI. Both places have two-factor authentication enabled. Therefore I have to do these things before I can access my repos via ssh:
- generate ssh keys
- add them to my accounts
- start ssh-agent
- ssh-add my ssh keys
GitHub has provided some good help doc for doing those. https://help.github.com/categories/ssh/
The problem is ssh-agent doesn’t save keys. I’ll have to do 3 and 4 every time when I start a new terminal session. It’d be nice to have my terminal automatically do those two steps whenever I start a new session.
I use Atom on Windows. For terminal I usually use a package called Platformio IDE terminal. This way I don’t have to launch another app (like Git Bash or PowerShell). With this package I can set start-up scripts, which is perfect for getting ssh ready in my scenario. Here’s my recipe:
Go to the settings page of this package, set the Shell Override: By default on Windows, it uses PowerShell. I found it hard to use SSH in PS, so I switched it to Windows cmd. I also tried Git Bash, but it will not stay inside a panel in Atom. It works, just not pretty.
- In the Settings page, write down these ssh commands in the “Auto Run Command” box.
start-ssh-agent.cmd && ssh-add ~/.ssh/id_rsa
You may need to specify the location of where your ssh keys are stored, if not in the default ~/.ssh/ folder. Also specify the key file names if you have more than one key like I do.
start-ssh-agent.cmd && ssh-add ~/.ssh/mykey_rsa && ssh-add ~/.ssh/myotherkey_rsa
See that “start-ssh-agent.cmd” above? It comes with Git for Windows. I use this provided script instead of the Linux way work-around
eval $(ssh-agent -s)because sometimes the eval thing can get confusing if I’m not using Git Bash.
- Now restart Atom and open a terminal panel to test if it works.
One way is to use this ssh command:
ssh -T email@example.com
The other way is to do a git fetch to your repo.