3.9 KiB
3.9 KiB
Configure a New Host
Prerequisites
- Fresh Debian 11+ installation on x86 hardware.
- SSH access to host.
Create Admin User
- Get su perms. Either via
sudo
,su -
, or by logging in as the root user. adduser admin
to create the non-root admin user.usermod -aG sudo admin
to add the new user to the sudo group.sudo visudo
and append this line to the end of the file:admin ALL=(ALL) NOPASSWD:ALL
to enable passwordless sudo.
After these, you can sudo su admin
to log into the new user account.
https://www.cyberciti.biz/faq/add-new-user-account-with-admin-access-on-linux/
https://www.cyberciti.biz/faq/linux-unix-running-sudo-command-without-a-password/
Set the Hostname
sudo hostnamectl set-hostname <hostname>
to set the hostname.sudo nano /etc/hosts
and edit the old value for127.0.1.1
to use the new hostname.
Configure Secure SSH
mkdir -p /home/admin/.ssh && echo "<insert pubkey here>" >> /home/admin/.ssh/authorized_keys
Add pubkey to authorized_keys. Make sure to place the correct SSH pubkey in the command before copying.sudo apt install libpam-google-authenticator
to install the Google 2FA PAM.google-authenticator
to configure the 2FA module. Use the following responses when prompted:
- Do you want authentication tokens to be time-based?
y
- Do you want me to update your "/home/$USER/.google_authenticator" file?
y
- Do you want to disallow multiple uses of the same authentication token?
y
- Do you want to do so?
n
(refers to increasing time skew window) - Do you want to enable rate-limiting?
y
We enter our TOTP secret key into our second authentication method and save our one-time backup recovery codes.
sudo nano /etc/pam.d/sshd
to edit the PAM configuration, and add this line to the top of the fileauth sufficient pam_google_authenticator.so nullok
5a. sudo nano /etc/ssh/sshd_config
to open the SSH daemon config for editing. Make sure the following assertions exist:
PubkeyAuthentication yes
AuthenticationMethods publickey,keyboard-interactive
PasswordAuthentication no
ChallengeResponseAuthentication yes
UsePAM yes
5b. echo $'PubkeyAuthentication yes\nAuthenticationMethods publickey,keyboard-interactive\nPasswordAuthentication no\nChallengeResponseAuthentication yes\nUsePAM yes' | sudo tee /etc/ssh/sshd_config.d/ssh.conf
to perform the above as a one-liner. Requires a version of OpenSSH/Linux that supports sourcing sshd config from the /etc/ssh/sshd_config.d/*.conf
path.
sudo systemctl restart sshd.service
to restart the SSH daemon.
Install Basic Packages
sudo apt install curl nano inxi git htop
Install Docker
curl -fsSL https://get.docker.com | sudo sh
This is the most convenient and least safe way to do this. If this script is ever compromised, we'd be fucked.sudo systemctl enable docker
to enable the Docker service.sudo usermod -aG docker $USER
to add the current user (should be non-root admin) to docker group.logout
to relog and apply the new permissions.
Clone the Homelab Repo
- Create a new Gitlab personal access token for the device at Personal Access Tokens. Should be named like
warlock
and have the following scopes:read_api
,read_user
,read_repository
. mkdir ~/homelab ~/data && cd ~/homelab/ && git init && git config core.sparseCheckout true && git config pull.ff only
to init the repository with sparse checkout enabled.git remote add -f origin https://<pat-name>:<pat-value>@gitlab.jafner.net/Jafner/homelab.git
to add the repo with authentication via read-only personal access token. NOTE: Make sure to replace<pat-name>
with the name of the personal access token, and replace<pat-value>
with the key for the personal access token.echo "$HOSTNAME/" > .git/info/sparse-checkout
to configure sparse checkout for the host.git checkout main
to switch to the main branch with the latest files.