The IT Alchemy Lab really doesn't have any set "purpose" to speak of. It is more about the IT technologies and issues I come across in my day-to-day business, meetings and chats (lunches, coffee and drinks) with my IT colleagues and friends.

Blog Archive

Saturday, July 11, 2015

Setting up ssh for Git on Windows


Something so simple, should never be this difficult. For the mac/osx/linux, this is a no-brainer as it's built right into your OS as a integral part. For windows users, not so lucky

Note:  replace all of the usages of spongebob with your actually account name.

Step 1:  Install the Git client

Grab git from here http://msysgit.github.io/  (you could probably use another one, but for this post - that's the choice).  If you already have it installed, and it is installed in the default location of "C:\Program Files (x86)\Git" - you will want to uninstall it.

Let's create a new home for our application. Use the command line or Explorer, either will get the job done.  Navigate to the root C:\ drive and create a new folder, 'opt'.  Call it what you want, but try and stick to lower case, alpha characters. Absolutely no spaces (thus the reason for moving it originally).
When you install Git, select the new folder c:\opt\Git. (for the rest of this example, that will be the folder we use - replace those values with whatever you actually use)

Select the middle option, 'Run Git from the Command Line'

Step 2:  Environment Variables

The following variables are all configured from the same location.  Open your system settings, find the 'Advanced system settings' link and bring up the Systems Properties window.
From here, on the bottom click the 'Environment Variables...' and another window should pop up (big love for the Windows OS ... #dryhumor)



These ARE Case sensitive. 

HOME Variable
This one is the only 'User Variable' we'll set. Click the top 'New' button.
Variable Name: HOME
Variable value: c:\Users\spongebob
Save it ...

The next three are System Variables. If you are not an admin, use all User Variables.
GIT_HOME
Click 'New'
Variable Name: GIT_HOME
Variable value: C:\opt\Git

GIT_SSH Variable
Click 'New'
Variable Name: GIT_SSH
Variable value: %GIT_HOME%\bin\ssh.exe

Path Variable
Scroll down and find the 'Path' entry, select it and click 'Edit...'
In the value box, move the cursor to the very front of the string, do not delete or change any existing values.   You will want to add the following (minus quotes)  "%GIT_HOME%/bin/;"

for example: if the path looks like this when you start:
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem; ....
it should look like this when click 'OK'
%GIT_HOME%/bin/;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem; ....

Close all of Windows' silly windows and make your way back to the Desktop.  Open a command prompt and lets test out our settings.  Type in: git and you should see the help instructions. 

If you see something like this ... we're in great shape. If not, walk through the instructions, might be missing a semicolon or have an extra white space somewhere.  


Step 4:  Generate an SSH key

Now to generate a key, open-ssh comes with Git. From the command prompt, enter the following:

ssh-keygen -t rsa

the place you want to save it is in your HOME (the value we used earlier: C:\Users\spongebob) plus .ssh\id_rsa  ... the final value should be:  C:\Users\spongebob\.ssh\id_rsa

Feel 100% free to rename it to anything you want:  github-personal,  github, spongebob-github ... etc

This is a personal preference, if you add a pass phrase to your key, every time you use it you will be asked to enter the password. Your call, I don't set one for the key I use for github.

Step 5:  Github

Head on over to https://github.com/ and either login or create a new account.
From the top right, click your profile window and select 'Settings', from the left, select 'SSH keys' and finally 'Add SSH key'.


In notepad, open the pub file we created earlier.  C:\Users\spongebob\.ssh\id_rsa.pub  copy it and paste it in. Do not paste the contents of the key without an extension (id_rsa) - that is your private key and you should never share that with anyone.



If your public key is on multiple lines, combine them.
If your key is missing the string 'ssh-rsa' at the beginning, you will need to add that as well.  If you try to add the key in Github without the string, it will bark at you.


Step X:  (Optional) Add an SSH config file

If you named your key something other than id_rsa, we need to do a little configuration.
Open your favorite text editor, and save the following file:  C:\Users\spongebob\.ssh\config

The body of the file should have these values:
Host github.com
    Hostname github.com
    User git
    IdentityFile ~/.ssh/spongebob-id_rsa

Step 6:  Put it all together

Now we test it out. Create a project on github called diamond-dave, save it, from the clone area (bottom right) click SSH, then click the button, it should copy the URL to your clipboard.

From the command prompt, type in: git clone git@github.com:spongebob/diamond-dave.git

After the project checks out ... celebrate ... but lets check one last thing.
cd into the project
touch README.md  (if you didn't already when you created the project)
open with your favorite editor, add the following.
If you created the file, add this
# Diamond-Dave

If it was already there, add to it
**No more passwords for me!**

Save the file and we have one final task:
enter the following commands:

git add .
git commit -am "pushing with no password"
git push origin master

Enjoy!



Wednesday, February 13, 2013

Command Line Socks Proxy commands on the Mac

Firewalls always cause developers problems (and I do not mean in the negative context), trying to hit code sites, blogs or other crowd sourcing sites ... after a little research I have come across a little trick that will get the job done

Step 1: create the connectivity file
standard ssh command, dropped into a shell script with the port forwarding flag added:
file:
socks.ssh
content:

#!/bin/bash
ssh -D 1080 username@myhomeserver.com


That's it, that simple ... so what did we just do?  SSH -D is for dynamic application-level port forwarding. Its syntax is ssh -D ${port} ${remote host}  This will allow you to drop a SOCKS proxy over an encrypted ssh tunnel, which leads us directly to ...

Step 2: SOCKS over SSH Tunnel
Now lets over ride the Mac security settings and skip all that silly administrative stuff ...

file:
socks.start
content:

#!/bin/bash
echo "Setting Socks Proxy to 'localhost 1080'"
networksetup -setsocksfirewallproxy "Wi-Fi" localhost 1080
echo "'Wi-Fi' Socks Proxy now pointing to 'localhost 1080'"
networksetup -setsocksfirewallproxy "Ethernet" localhost 1080
echo "'Ethernet' Socks Proxy now pointing to 'localhost 1080'"


This will point all of your outgoing data through your ssh tunnel - averting the firewall and security setup by your administrators

Now we need a way to stop/disable these settings:

file:
socks.stop
content:

#!/bin/bash
echo "Disabling Socks Proxy from 'localhost 1080'"
networksetup -setsocksfirewallproxystate "Wi-Fi" off
networksetup -setsocksfirewallproxystate "Ethernet" off
echo "'Wi-Fi' and 'Ethernet' Socks Proxy now set to 'off'"

Pretty simple ... you will need to set the files as executable: chmod +x socks.ssh socks.start socks.stop




About Me

My photo
Don't tell people how to do things, tell them what to do and let them surprise you with their results. --General George S. Patton
Open Source Links | Sourceforge | Slashdot | Open Source