I was looking for a method to restrict access to a private Debian repository and be able to authenticate to it non-interactively (i.e. using a script)
The most useful article I found if actually one from Debian administration site but the secure method uses ssh and public/private keys. It works great but each host's public key needs to be inside the remote authorized_keys file to successfully authenticate. It doesn't says nothing about providing password to ssh:// but I suppose it should be possible.
Have you tried other alternatives (e.g. ftps)?
Thanks in advance
If you always run
apt-get
on your servers by hand (no automaticapt-get
commands launched by crons), then you might consider using ssh agent forwarding. This avoids having to manage one public/private keypair per server you manage, and it's probably safer than leaving private keys on every server.Initial configuration - connect to the servers you want to manage, and add something like this to
/etc/apt/sources.list
(this example assumes you want your servers to connect to themanager
account):create a pair of private/public keys on your own computer, with your login
johndoe
for example (provided your computer runs on debian: if not, you can do this from a debian server dedicated to management):copy your public key to the repository server in
/home/manager/.ssh/authorized_keys
:Once per management session
start the ssh agent on your machine by typing:
add your key to the agent (this will require your passphrase):
Managing a server
connect to the server you want to manage using
ssh -A
(-A
activates agent forwarding):switch to root (if you want to use
sudo
you need to configure/etc/sudoers
or elsesudo
will break agent forwarding, read this):you should now be able to connect to the repository's manager account using ssh without typing your password again, thanks to agent forwarding. Therefore,
apt-get
should work just fine:Ending your management session
Once you have finished managing your servers, remove your keys from the agent:
Advantages
ssh-ask
in order to accept/refuse every attempt to use your key.One way to do this is just to allow a certain set of IPs to access the repository. This works very well for LAN and VPN.
Simple and efficient.
The ssh + public/private keys solution is not that bad:
ssh-keygen
, thenssh-copy-id [email protected]
edit
/etc/apt/sources.list
and add something like:Granted, it requires you to put each server's public key in the
~/.ssh/authorized_keys
file on the server, but it's not that complicated (see above) and it gives you control over which servers you allow or not at any given time (you can remove a key at any time inauthorized_keys
).You could setup an https access to your repository, secured by login/password (basic authentication). The problem is that you need to put the cleartext login/password in
/etc/apt/sources.list
(note: there is a patch to allow the login/password to be put in/root/.netrc
instead).The link in your question shows multiple methods. You want number 2, https + basic authentication.