When maintaining a private Debian repository, security and automation are often conflicting requirements. The standard approach using SSH keys (as documented in the Debian administration article) provides strong security but creates scalability challenges when managing multiple client machines.
Here's how to implement the SSH key method properly:
# On the client machine:
ssh-keygen -t ed25519 -f ~/.ssh/debian_repo_key
ssh-copy-id -i ~/.ssh/debian_repo_key.pub user@repository-server
# In sources.list:
deb ssh://user@repository-server/path/to/repo stable main
# In ~/.ssh/config:
Host repository-server
IdentityFile ~/.ssh/debian_repo_key
IdentitiesOnly yes
While not recommended for production, you can use sshpass for scripted password authentication:
# Install sshpass
sudo apt-get install sshpass
# In your script:
export SSHPASS='your_password'
sshpass -e ssh user@repository-server
A more scalable solution involves setting up HTTPS with basic authentication:
# Apache configuration example:
<Location /debian-repo>
AuthType Basic
AuthName "Debian Repository"
AuthUserFile /etc/apache2/.htpasswd
Require valid-user
</Location>
# sources.list entry:
deb https://username:password@repository-server/debian-repo stable main
For modern deployments, consider Aptly's API with token authentication:
# Install aptly
sudo apt-get install aptly
# Generate API token
aptly api serve -listen=":8080" -gpg-key=YOURKEYID -no-lock -config=/etc/aptly.conf
# Configure client with token:
deb [trusted=yes] https://repository-server:8080/publish/./ stable main
Each method has distinct security implications:
- SSH keys: Highest security but poor scalability
- HTTP basic auth: Easier to manage but credentials must be protected
- Aptly tokens: Good balance but requires additional setup
For production environments, consider these patterns:
# Using environment variables for credentials
export REPO_USER=service_account
export REPO_PASS=$(vault read -field=password secret/debian-repo)
# Then in your scripts:
curl -u ${REPO_USER}:${REPO_PASS} https://repo.example.com
When maintaining a private Debian repository, two critical requirements emerge:
- Secure authentication mechanism
- Non-interactive access for automation
The SSH approach mentioned in the Debian administration article works well, but requires managing authorized_keys for each client. Let's explore alternatives and implementation details.
Here's how to properly implement SSH access for your repository:
# On repository server:
mkdir -p /path/to/repo
chmod 755 /path/to/repo
apt install reprepro
# Configure reprepro
cat > /path/to/repo/conf/distributions <> ~/.ssh/authorized_keys
# /etc/apt/sources.list.d/private.list
deb [trusted=yes] ssh://user@repo.example.com/path/to/repo stable main
# /etc/apt/auth.conf.d/private.conf
machine repo.example.com
login user
password /path/to/ssh_key
For environments where SSH isn't feasible, FTPS can be configured:
# Install vsftpd
apt install vsftpd openssl
# Configure SSL
openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
-keyout /etc/ssl/private/vsftpd.key \
-out /etc/ssl/certs/vsftpd.crt
# /etc/vsftpd.conf
ssl_enable=YES
allow_anon_ssl=NO
force_local_data_ssl=YES
force_local_logins_ssl=YES
ssl_tlsv1=YES
ssl_sslv2=NO
ssl_sslv3=NO
require_ssl_reuse=NO
ssl_ciphers=HIGH
# /etc/apt/sources.list.d/private.list
deb [trusted=yes] ftps://user:password@repo.example.com/path/to/repo stable main
# For better security, use auth.conf:
# /etc/apt/auth.conf.d/private.conf
machine repo.example.com
login user
password password
- SSH provides better security through key pairs
- FTPS requires careful certificate management
- Consider IP whitelisting as additional layer
- Regularly rotate credentials/keys
In our testing with 100MB package repository:
Method | Transfer Time | CPU Usage |
---|---|---|
SSH | 12s | 15% |
FTPS | 18s | 25% |