Created
December 9, 2023 18:28
-
-
Save snigdhasjg/4038c0cecdcecab5ad9a6f5b01b9f8f8 to your computer and use it in GitHub Desktop.
git local server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Location ~/.ssh/config | |
Host localhost | |
Port 8022 | |
Hostname localhost | |
IdentityFile ~/.ssh/id_rsa_common | |
UserKnownHostsFile /dev/null | |
StrictHostKeyChecking no |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '3.9' | |
services: | |
git: | |
container_name: git | |
build: | |
context: . | |
ports: | |
- "8022:22" | |
volumes: | |
- git_repo:/home/git/repositories | |
volumes: | |
git_repo: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Use the official Ubuntu image as the base image | |
FROM ubuntu:22.04 | |
# Install OpenSSH server | |
RUN apt update && apt install -y openssh-server git | |
# Create an app user with git-shell | |
RUN useradd -ms /bin/bash -s $(which git-shell) git | |
# Switch as git user | |
USER git | |
WORKDIR /home/git | |
# Enable SSH public key-based authentication | |
RUN mkdir -m 700 .ssh git-shell-commands | |
COPY --chown=git:git --chmod=600 ./authorized_keys .ssh/ | |
RUN mkdir -p repositories/project.git | |
RUN cd repositories/project.git && \ | |
git config --global init.defaultBranch main && \ | |
git init --bare | |
# Switch back to root user | |
USER root | |
WORKDIR /var/run/sshd | |
# Expose SSH port | |
EXPOSE 22 | |
# Start SSH server | |
CMD ["/usr/sbin/sshd", "-D"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git clone git@localhost:/git/project2/.git |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment