Skip to content

Instantly share code, notes, and snippets.

@sahwar
Forked from itsabdelrahman/linux-server-setup.md
Created April 11, 2022 12:02
Show Gist options
  • Save sahwar/8c036d935c506cb4883d3ecf65d27b44 to your computer and use it in GitHub Desktop.
Save sahwar/8c036d935c506cb4883d3ecf65d27b44 to your computer and use it in GitHub Desktop.
Linux Ubuntu/Debian Server Setup

Linux Ubuntu/Debian Server Setup

On remote machine

As root

  1. Change root password
    • $ passwd
  2. Create user & their home directory
    • $ useradd -m <username>
  3. Set user's password
    • $ passwd <username>
  4. Make user a sudoer
    • $ usermod -aG sudo <username>
  5. Set user's shell as bash
    • $ chsh -s /bin/bash <username>
  6. Disconnect SSH session

As <username>

  1. Install essentials
    • Update & upgrade
      • $ sudo apt update && sudo apt upgrade
    • Install tools
      • $ sudo apt install nano curl git htop mlocate dnsutils tmux tree fzf
    • Build locate's index
      • $ sudo updatedb
  2. Enable passwordless sudo for user
    • $ sudo nano /etc/sudoers
    • Add: <username> ALL=(ALL) NOPASSWD: ALL

On local machine

  1. Copy SSH public key to remote machine's authorized keys
    • $ ssh-copy-id -i <public-key-path> <username>@<remote-machine-ip-address>

On remote machine

As <username>

  1. Edit SSH daemon configuration
    • $ sudo nano /etc/ssh/sshd_config
    • Disable root access
      • Edit: PermitRootLogin no
    • Disable password authentication
      • Edit: PasswordAuthentication no
    • Restart ssh service: $ sudo /etc/init.d/ssh restart
  2. Set ZSH as default shell
    • $ sudo apt install zsh
    • $ sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
  3. Configure locale (if not English)
  4. Install Docker
  5. Install Docker Compose
  6. Schedule cleanup of unused Docker images
    • Open crontab
      • $ crontab -e
    • Create a new cronjob
      • Append: 0 1 * * * sudo docker system prune -af
  7. Facilitate pushing to ssh git remotes
    • $ git config receive.denyCurrentBranch updateInstead
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment