Macbook Air Server
Introduction
My old MacBook Air M2 has retired from being my daily driver and has been moved into the basement, next to the server rack.
Instead of using an old Raspberry Pi 3 Model B, I would like to repurpose my Mac to serve as a dedicated server.
Setup Remote Access
- Open System Settings.
- Navigate to General > Sharing
- Turn on the toggle for Remote Management
- Set access for my user.
- (Optional) Enable Remote Login toggle for SSH.
On the new server, ensure that the ssh file and directory permissions are valid.
On local machine, copy the contents of the public key and paste it into the remote machine. cat ~/.ssh/id_ed25519.pub | pbcopy.chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
Ensure that the ssh permissions in the remote machine are configured to disable password authentication.
sudo vim /etc/sshd/config...
PasswordAuthentication no
UsePAM no
ChallengeResponseAuthentication no
Additional Steps
I want my MacBook to run even with the lid closed. To do this, I disabled sleep mode.sudo pmset -a disablesleep 1
Setup Caddy
Created a new folder ~/Documents/Caddy and added the following files:
compose.ymlservices:
caddy:
# image: caddy:<version>
build: .
environment:
- CLOUDFLARE_API_TOKEN=${CLOUDFLARE_API_TOKEN}
restart: unless-stopped
ports:
- "80:80"
- "443:443"
- "443:443/udp"
volumes:
- ./conf:/etc/caddy
- ./site:/srv
- caddy_data:/data
- caddy_config:/config
extra_hosts:
- "host.docker.internal:host-gateway"
volumes:
caddy_data:
caddy_config:# syntax=docker/dockerfile:1
FROM caddy:2.10.2-builder AS builder
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
xcaddy build \
--with github.com/caddy-dns/cloudflare
FROM caddy:2.10.2
COPY --from=builder /usr/bin/caddy /usr/bin/caddy
conf/Caddyfile{
email [email protected]
}
firefly.u0.vc {
tls {
dns cloudflare {env.CLOUDFLARE_API_TOKEN}
}
# reverse_proxy 127.0.0.1:8081
reverse_proxy host.docker.internal:8081
}
home.u0.vc {
tls {
dns cloudflare {env.CLOUDFLARE_API_TOKEN}
}
reverse_proxy 10.242.242.174:8123
}
# Example for a simple local file server
:80 {
respond "Hello World!"
}
DNS records have been updated on the router itself to point to the laptop.