VOOZH about

URL: https://thenewstack.io/create-a-local-git-repository-on-linux-with-the-help-of-ssh/

⇱ Create a Local Git Repository on Linux with the Help of SSH - The New Stack


TNS
SUBSCRIBE
Join our community of software engineering leaders and aspirational developers. Always stay in-the-know by getting the most important news and exclusive content delivered fresh to your inbox to learn more about at-scale software development.
REQUIRED
It seems that you've previously unsubscribed from our newsletter in the past. Click the button below to open the re-subscribe form in a new tab. When you're done, simply close that tab and continue with this form to complete your subscription.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.
Welcome and thank you for joining The New Stack community!
Please answer a few simple questions to help us deliver the news and resources you are interested in.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Great to meet you!
Tell us a bit about your job so we can cover the topics you find most relevant.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Welcome!

We’re so glad you’re here. You can expect all the best TNS content to arrive Monday through Friday to keep you on top of the news and at the top of your game.

What’s next?

Check your inbox for a confirmation email where you can adjust your preferences and even join additional groups.

Follow TNS on your favorite social media networks.

Become a TNS follower on LinkedIn.

Check out the latest featured and trending stories while you wait for your first TNS newsletter.

PREV
1 of 2
NEXT
VOXPOP
As a JavaScript developer, what non-React tools do you use most often?
Angular
0%
Astro
0%
Svelte
0%
Vue.js
0%
Other
0%
I only use React
0%
I don't use JavaScript
0%
Thanks for your opinion! Subscribe below to get the final results, published exclusively in our TNS Update newsletter:
NEW! Try Stackie AI
From clobbered drafts to real-time sync
Apr 14th 2026 10:00am, by David Moore
TypeScript 6.0 RC arrives as a bridge to a faster future
Mar 14th 2026 9:00am, by Darryl K. Taft
Mastra empowers web devs to build AI agents in TypeScript
Jan 28th 2026 11:00am, by Loraine Lawson
2022-11-05 06:00:09
Create a Local Git Repository on Linux with the Help of SSH
tutorial,
CI/CD / Linux / Open Source / Software Development

Create a Local Git Repository on Linux with the Help of SSH

Have you ever found yourself in a situation where you need to deploy a quick Git repository on a machine within your LAN? Here's what to do.
Nov 5th, 2022 6:00am by Jack Wallen
👁 Featued image for: Create a Local Git Repository on Linux with the Help of SSH

Have you ever found yourself in a situation where you need to deploy a quick Git repository on a machine within your LAN? If you’re a developer, chances are pretty good this task has fallen into your lap on several occasions.

Fortunately, you don’t really need to depend on a bunch of overly complicated software packages or third-party tools to make this happen. Sure, if you want a sweet GUI to make the lives of all those who will contribute to your development project considerably easier, you might turn to a platform like Gitea. But if you prefer the simplicity and ease of deployment that comes along with the command line, you’re going to want to give this method a go. It might not have all the bells and whistles of the web-based options but it does the job reliably and quickly.

And so, how do you deploy this magical repository? With the help of git and SSH. Both of these tools are freely available to all Linux distributions, so you don’t have to worry about searching out or paying for the tools.

Sound like a winner? I thought so. Let’s make it happen.

All the Things You’ll Need

To make this work, you’re going to need a Linux distribution to host the repository, another machine to use the repository, and a user with sudo privileges. I’ll be demonstrating on Ubuntu Server 22.04 but I’ll also show how to install the software on an RHEL/Fedora-based Linux distribution.

Ready? I thought so.

Instal the Necessary Software

The first thing we’ll do is install the necessary software. The only two packages you need are SSH and Git. Most likely SSH is already installed (as it is with nearly every Linux distribution on the planet). Git, on the other hand, may not be found on your machine. So, to install Git on a Ubuntu-based distribution, you’d issue the command:

sudo apt-get install git -y

If you’re on an Red Hat Enterprise Linux/Fedora-based distribution, that command would be:

sudo dnf install git -y

One thing to keep in mind is that you must install git on the machine hosting the repository and the one using the repository.

Create a Special User

We’re now going to create a special account that will be used for the purposes of this repository. For that, the command will be the same, regardless of what distribution you use, and is done on the machine hosting the repository. To create the user, issue the command:

sudo adduser git

The adduser command should require you to set a password for the user. If not, do so with:

sudo passwd git

Change to this new user with:

su git

Change into the git user’s home directory with:

cd

Now, we need to create an .ssh directory with the command:

mkdir .ssh

Give that directory the proper permissions with:

chmod 700 .ssh

The next step is to create the authorized_keys file with the command:

touch .ssh/authorized_keys

Give that file the required permissions with:

chmod 600 .ssh/authorized_keys

Create an SSH Key on the Local Machine and Copy It to the Repository Machine

Next, we need to create an SSH key on the machine you’ll use to access the repository. For that, log into the client machine and issue the command:

ssh-keygen

Once the key is generated, you’ll need to copy the contents of the key. First view the key with:

cat /home/USER/.ssh/id_rsa.pub

Where USER is your username.

Back on the machine hosting the repository open the authorized_keys file with:

nano /home/git/.ssh/authorized_keys

Paste the contents of the SSH key into this file and save/close it.

Create the New Repository

On the machine hosting the repository, create a new directory with the command:

mkdir /home/git/git_repo

Change into that new directory with the command:

cd /home/git/git_repo

Create a new project folder with a command like this:

mkdir PROJECT

Of course, you can name the folder whatever you like.

Change into that folder with:

cd PROJECT

Initialize the repository with:

git --init bare

Clone the New Repository

Head back to the client machine and clone the new repository with the command:

git clone git@SERVER:/home/git/git_repo/PROJECT

Where  SERVER is the IP address of the server hosting the repository and PROJECT is the name of the project folder.

You’ll be prompted for the SSH key password. Upon successful authentication, the contents of the project folder will be pulled to your local machine.

You can now add your first commit (let’s add a README) and push the changes back to the repository with:

touch README
git add --all
git commit -m "Added README file"
git push origin master

There you go. You’ve just created a quick Git repository. If you need to give other users access to the repository, you should only need to have them create SSH keys on their machines and copy them to the server in the same way you did above.

Congratulations on getting a Git repository up and running in mere minutes.

TRENDING STORIES
Jack Wallen is what happens when a Gen Xer mind-melds with present-day snark. Jack is a seeker of truth and a writer of words with a quantum mechanical pencil and a disjointed beat of sound and soul. Although he resides...
Read more from Jack Wallen
SHARE THIS STORY
TRENDING STORIES
SHARE THIS STORY
TRENDING STORIES
TNS DAILY NEWSLETTER Receive a free roundup of the most recent TNS articles in your inbox each day.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.