Blog Tinux Net

Almalinux

Configuraciones y comandos utiles para configurar el servidor almalinux

  • Publicado en

    I'll help you set up a Git server on AlmaLinux. Here's a comprehensive guide:

    Installing Git Server on AlmaLinux

    1. Update System and Install Git

    sudo dnf update -y
    sudo dnf install git -y
    

    2. Create a Git User

    sudo adduser git
    sudo passwd git
    

    3. Set Up SSH Access

    # Switch to git user
    sudo su - git
    
    # Create .ssh directory
    mkdir ~/.ssh && chmod 700 ~/.ssh
    touch ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys
    

    4. Create a Git Repository

    # Create a directory for repositories
    sudo mkdir -p /srv/git
    sudo chown git:git /srv/git
    
    # Switch to git user and create a bare repository
    sudo su - git
    cd /srv/git
    git init --bare myproject.git
    

    5. Configure Firewall (if needed)

    sudo firewall-cmd --permanent --add-service=ssh
    sudo firewall-cmd --reload
    

    6. Client Setup - Add SSH Key

    On your client machine:

    # Generate SSH key if you don't have one
    ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
    
    # Copy your public key to the git server
    ssh-copy-id git@your-server-ip
    

    Or manually add your public key to /home/git/.ssh/authorized_keys on the server.

    7. Clone and Use the Repository

    From your client machine:

    # Clone the repository
    git clone git@your-server-ip:/srv/git/myproject.git
    
    # Navigate to the directory
    cd myproject
    
    # Add files and push
    echo "# My Project" >> README.md
    git add README.md
    git commit -m "Initial commit"
    git push origin master
    

    Alternative: Install Gitea (Web-based Git Service)

    If you want a GitHub-like interface:

    # Install dependencies
    sudo dnf install git wget -y
    
    # Download Gitea
    wget -O /tmp/gitea https://dl.gitea.io/gitea/1.21/gitea-1.21-linux-amd64
    sudo mv /tmp/gitea /usr/local/bin/gitea
    sudo chmod +x /usr/local/bin/gitea
    
    # Create git user and directories
    sudo adduser --system --shell /bin/bash --group --disabled-password --home /home/git git
    sudo mkdir -p /var/lib/gitea/{custom,data,log}
    sudo chown -R git:git /var/lib/gitea/
    sudo chmod -R 750 /var/lib/gitea/
    
    # Create systemd service
    sudo nano /etc/systemd/system/gitea.service
    

    Add this content to the service file:

    [Unit]
    Description=Gitea
    After=syslog.target
    After=network.target
    
    [Service]
    RestartSec=2s
    Type=simple
    User=git
    Group=git
    WorkingDirectory=/var/lib/gitea/
    ExecStart=/usr/local/bin/gitea web --config /etc/gitea/app.ini
    Restart=always
    Environment=USER=git HOME=/home/git GITEA_WORK_DIR=/var/lib/gitea
    
    [Install]
    WantedBy=multi-user.target
    
    # Start Gitea
    sudo systemctl enable gitea
    sudo systemctl start gitea
    
    # Open firewall port (default 3000)
    sudo firewall-cmd --permanent --add-port=3000/tcp
    sudo firewall-cmd --reload
    

    Access Gitea at http://your-server-ip:3000

    Security Tips

    1. Disable shell access for git user:

      sudo usermod -s /usr/bin/git-shell git
      
    2. Use SSH keys only (disable password authentication)

    3. Set up proper file permissions on repository directories

    4. Enable SELinux and configure it properly

    5. Keep system updated regularly

    Pasos para interactuar con el git remoto desde tu ubicación local.

    git remote add origin git@git.servidor.net:/srv/git/miproyecto.git
    

    Pasos Completos

    1. Añadir el repositorio remoto:
    git remote add origin git@git.servidor.net:/srv/git/miproyecto.git
    
    1. Verificar que se añadió correctamente:
    git remote -v
    

    Deberías ver algo como:

    origin  git@git.servidor.net:/srv/git/miproyecto.git (fetch)
    origin  git@git.servidor.net:/srv/git/miproyecto.git (push)
    
    1. Hacer tu primer commit (si aún no lo has hecho):
    git add .
    git commit -m "Primer commit"
    
    1. Subir los cambios al servidor:
    git push -u origin master
    # o si usas 'main' como rama principal:
    git push -u origin main
    

    Si ya Añadiste el Remote Incorrectamente

    Si ya ejecutaste el comando incorrecto y necesitas corregirlo:

    # Ver los remotes actuales
    git remote -v
    
    # Si existe un remote incorrecto, eliminarlo
    git remote remove origin
    
    # Añadir el remote correcto
    git remote add origin git@git.servidor.net:/srv/git/miproyecto.git
    

    Solución de Problemas de Conexión

    Si tienes problemas conectando al servidor, verifica:

    1. Conexión SSH:
    ssh git@git.servidor.net
    
    1. Permisos del repositorio en el servidor:
    # En el servidor
    ls -la /srv/git/miproyecto.git
    
    1. Tu clave SSH está configurada:
    ssh-add -l
    

    ¿Te funciona ahora con el comando correcto?