Now that I was somewhat comfortable using Git for version control, I immediately felt the need to create some private repos. I needed a remote repository to backup my work. One option was to get a paid account with the good folks at the GitHub, or use my Linux hosting package at 1&1. I chose the later. I use
GIT for Windows. By the way, Git already comes installed on the Linux servers on 1&1. I wanted to use a secured connection to the server. So, here are the steps to create a secured remote repository on a Linux server, hosted at 1&1. Keep in mind that these instructions are primarily for Git for Windows client, however, they can be used for other clients as well with subtle differences in the folders etc. I am sorry for being over-detailed, but one of these small missteps get you from being successful.
- Make sure you have ssh access to the server. You can get the information from your 1&1 control panel. Test it using the popular ssh client, Putty.
- On you Windows machine, get the location of Git for Windows.
You will see folders like:
C:\Users\{User}\ AppData\Local\GitHub\PortableGit_{guid}\bin
C:\Users\{User}\AppData\Local\GitHub\PortableGit_{guid}\cmd
Example:
C:\Users\bender\AppData\Local\GitHub\PortableGit_c2ba306e536fdf878271f7fe636a147ff37326ad\bin
Bender is my windows login. - Add both folders to your path. See below.
- Test the prior step by typing the following in a command prompt.
git --version
- Create folder .ssh under:
rem Fix the folder name to suit to your environment. md C:\Users\{User}\AppData\Local\GitHub\PortableGit_{guid}\.ssh
-
Open a command prompt, switch to this .ssh folder, and run the following commands. For now do not choose a pass phrase for the private key.
cd C:\Users\{User}\AppData\Local\GitHub\PortableGit_{guid}\.ssh rem Generate the private and public keys. ssh-keygen -t rsa rem This step will ask for pass phrase to encrypt your private key. rem For now just hit enter to skip. rem Pass phrase should be used, however, it requires extra steps to avoid rem being prompted for it every time you interact with the repo.
- The ssh-keygen step, would create private and the public keys as id_rsa and id_rsa.pub.
- Ftp id_rsa.pub to the 1&1 server to .ssh folder under your home folder. If you are not sure just ftp it to some place on the server.
-
Log into the 1&1 server using Putty and type the following commands:
# Switch to home folder cd ~ # Create .ssh folder undre home folder. # It may give error, if one exists already. # No problem. Just proceed. mkdir ~\.ssh # Add contents of id_rsa.pub to authorized_keys file under .ssh folder. # This is the same file which you Ftp-ed to the server. cat id_rsa.pub >> ~\.ssh\authorized_keys # Verify if authorized_keys exists. ls -al ~/.ssh/authorized_keys # Create a folder to hold your remote repos. mkdir ~/gitrepos # Create your first repository (mylabs) mkdir ~/gitrepos/mylabs cd ~/gitrepos/mylabs git init --bare # You are done with the server for now.
- Come back to the Windows machine. Open a command prompt and test your ssh connection using the private key. In my example below, 1&1 user id is u1234567 and my hosted domain is xyz.com.
ssh u1234567@www.xyz.com ls # If all goes well, you should see the directory listing from 1&1 server. # If that happens you are ready to use the remote repo.
-
Create a local repository. In my example the location is c:\mylabs.
cd c:\mylabs git init rem Add all existing files and folders to the repo. git add . rem Commit the newly added files. git commit -m "My first commit, hurray!" rem Add the 1&1 server as a remote server with alias origin. git remote add origin ssh://u1234567@www.xyz.com/~/gitrepos/mylabs rem Sync the commited changes to 1&1 server git push --set-upstream origin master # set upstream is required only for the first time. # Because you are pushing the changes to a blank repo on the server. # Future sync would be as following: git push origin master
-
You can test your prior step by cloning the repo from 1&1 server to c:\temp folder.
cd c:\temp git clone ssh://u1234567@www.xyz.com/~/gitrepos/mylabs rem You will see files and folders in c:\temp\mylabs folder.
View comments