Ubuntu 16.04 Create LAN Repository with Reprepro

unless you work in a homogeneously linux shop, you’re unlikely to even think about setting up your own local repository where your internal servers can grab .deb packages from. the package manager apt-get searches for, downloads, and installs the package for you. a repository in linux terms is simply the collection of packages, but almost nothing in the *nix world is as simple as it seems. especially when you have the sometimes unwanted personality trait called perfectionist. a repository can be viewed as the same concept as a caching proxy server, except it is for application packages that you would like to maintain and make available inside your internal network. you can make it public as well, but my article will focus on the use case of creating an internal repository for ubuntu 16.04 (codename xenial).

whenever i determine a task somewhat hard to accomplish due to a lack of resources through search engines like google, i like to document my work and post it as a blog on my website. sometimes i even use my own website as reference material because i after a while of not using some knowledge, it inevitably gets tossed into the garbage. how long does it take you to forget material after not using it? or maybe it’s the early onset of alzheimer’s


  • two ubuntu 16.04 lts virtual machines
  • patience

by the end of the guide you will have:

  • prepared and published a repository signing key
  • set up a repository with reprepro, the repository manager
  • made the repository accessible to internal servers with nginx
  • added the repository on another server
  • tested pulling and installing a package from your own local repo

first, we need a valid package signing key. this step is crucial for a secure repository, since we will be digitally signing all the packages. package signing gives the downloader confidence that the source can be trusted.

in this section, you will generate an encrypted master public key and a signing sub-key by following these steps:

  • generate a master key
  • generate a subkey for package signing
  • detach master key from subkey

let’s make the master key. this key should be kept safe and secure since this is what people will be trusting.

before we begin, let’s install rng-tools though apt-get:

apt-get install rng-tools

gpg requires random data, called entropy, to generate keys. entropy is normally generated over time by the linux kernel and stored in a pool. however, on cloud servers, the kernel may have trouble generating the amount of entropy required by gpg. to help the kernel, we install the rngd program (found in the rng-tools package). this program will ask the host server for entropy. once retrieved, rngd will add the data to the entropy pool to be used by other applications like gpg.

if you get a message like this:

trying to create /dev/hwrng device inode...
starting hardware rng entropy gatherer daemon: (failed).
invoke-rc.d: initscript rng-tools, action "start" failed.
start the rngd daemon manually with:
rngd -r /dev/urandom

by default rngd looks for a special device to retrieve entropy from /dev/hwrng. some virtual machines do not have this device. to compensate we use the pseudo random device /dev/urandom by specifying the -r directive. for more information, you can check out the rng-tools wiki page.

now that we have a pool of entropy, we can generate the master key. do this by invoking the command gpg. you will see a prompt similar to the following:

gpg --gen-key
gpg (gnupg) 1.4.16; copyright (c) 2013 free software foundation, inc.
this is free software: you are free to change and redistribute it.
there is no warranty, to the extent permitted by law.


please select what kind of key you want:
(1) rsa and rsa (default)
(2) dsa and elgamal
(3) dsa (sign only)
(4) rsa (sign only)
your selection? 1

specify the first option, “rsa and rsa (default)” 1, in the prompt. selecting this will have gpg generate first a signing key, then a encryption subkey (both using the rsa algorithm). we don’t need an encryption key for this tutorial, but as a great person once said, “why not?” there is no disadvantage in having both, and you may use the key for encryption in the future.

hit enter and you’ll be prompted for a keysize:

rsa keys may be between 1024 and 4096 bits long.
what keysize do you want? (2048) 4096

the key size correlates directly to how secure you want your master key to be. the higher the bit size, the more secure key. the debian project recommends using 4096 bits for any signing key, so i would specify 4096 here. for the next 2-5 years the default bit size 2048 is sufficient if you’d rather use that. a size of 1024 is uncomfortably close to being unsafe and should not be used.

press enter for the expire prompt.

please specify how long the key should be valid.
0 = key does not expire
<n>  = key expires in n days
<n>w = key expires in n weeks
<n>m = key expires in n months
<n>y = key expires in n years
key is valid for? (0) 0

master keys do not normally have expiration dates, but set this value as long as you expect to use this key. if you only plan to use this repository for only the next 6 months you can specify 6m. 0 will make it valid forever.

hit enter, then y. you will be prompted to generate a user id. this information will be used by others and yourself to identify this key – so use real information!

you need a user id to identify your key; the software constructs the user id

from the real name, comment and email address in this form:

"first last (first last) <firstlast@company.com>"
real name: travis runyard
email address: travis.runyard@example.com
you selected this user-id:
"travis runyard <travis.runyard@example.com>"
change (n)ame, (c)omment, (e)mail or (o)kay/(q)uit? o

if the information is correct, hit o and enter. we need to add a password to ensure that only you have access to this key. make sure to memorize this password since there is no way to recover a gpg key password (a good thing).

you need a passphrase to protect your secret key.
enter passphrase: (hidden)
repeat passphrase: (hidden)

now for some magic (math) to happen. this might take a little while, so sit back or get a cup of your favorite drink.

we need to generate a lot of random bytes. it is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
not enough random bytes available.  please do some other work to give
the os a chance to collect more entropy! (need 300 more bytes)
we need to generate a lot of random bytes. it is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
gpg: /root/.gnupg/trustdb.gpg: trustdb created
gpg: key 10e6133f marked as ultimately trusted
public and secret key created and signed.
gpg: checking the trustdb
gpg: 3 marginal(s) needed, 1 complete(s) needed, pgp trust model
gpg: depth: 0  valid:   1  signed:   0  trust: 0-, 0q, 0n, 0m, 0f, 1u
pub   4096r/10e6133f 2014-08-16
key fingerprint = 1cd3 22ed 54b8 694a 0975  7164 6c1d 28a0 10e6 133f
uid                  travis runyard <travis.runyard@example.com>
sub   4096r/7b34e07c 2014-08-16

now we have a master key. the output shows that we created a master key for signing (`0e6133f on the pub line above). your key will have different ids. make note of your signing key’s id (the example uses 10e6133f). we’ll need that information in the next steps when creating another subkey for signing.

generate a subkey for package signing

now we’ll create a second signing key so that we don’t need the master key on this server. think of the master key as the root authority that gives authority to subkeys. if a user trusts the master key, trust in a subkey is implied.

in the terminal execute:

gpg --edit-key 10e6133f

replace the example id with your key’s id. this command enters us into the gpg environment. here we can edit our new key and add a subkey. you’ll see the following output:

gpg (gnupg) 1.4.16; copyright (c) 2013 free software foundation, inc.
this is free software: you are free to change and redistribute it.
there is no warranty, to the extent permitted by law.
secret key is available.
pub  4096r/10e6133f  created: 2014-08-16  expires: never       usage: sc
trust: ultimate      validity: ultimate
sub  4096r/7b34e07c  created: 2014-08-16  expires: never       usage: e
[ultimate] (1). travis runyard <travis.runyard@example.com>

at the prompt, type addkey:


press enter. gpg will prompt for your password. enter the password that you used to encrypt this key.

key is protected.
you need a passphrase to unlock the secret key for
user: "travis runyard <travis.runyard@example.com>"
4096-bit rsa key, id 10e6133f, created 2014-08-16
gpg: gpg-agent is not available in this session
enter passphrase: <hidden>

you will see the following prompt for key type.

please select what kind of key you want:
(3) dsa (sign only)
(4) rsa (sign only)
(5) elgamal (encrypt only)
(6) rsa (encrypt only)
your selection? 4

we want to create a signing subkey, so select “rsa (sign only)” 4. rsa is faster for the client, while dsa is faster for the server. we’re picking rsa in this case because, for every signature that we make on a package, possibly hundreds of clients will need to verify it. the two types are equally secure.

again we are prompted for a key size.

rsa keys may be between 1024 and 4096 bits long.
what keysize do you want? (2048) 4096

this tutorial uses 4096 for increased security.

please specify how long the key should be valid.
0 = key does not expire
<n>  = key expires in n days
<n>w = key expires in n weeks
<n>m = key expires in n months
<n>y = key expires in n years
key is valid for? (0) 1y

we already have a master key, so the expiration time for the subkey is less important. one year is a good time frame.

hit enter, and then type y (yes) twice for the next two prompts. some math will generate another key.

we need to generate a lot of random bytes. it is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
pub  4096r/10e6133f  created: 2014-08-16  expires: never       usage: sc
trust: ultimate      validity: ultimate
sub  4096r/7b34e07c  created: 2014-08-16  expires: never       usage: e
sub  4096r/a72db3ef  created: 2014-08-16  expires: 2015-08-16  usage: s
[ultimate] (1). travis runyard <travis.runyard@example.com>

type save at the prompt.


in the output above, the sc from our master key tells us that the key is only for signing and certification. the e means the key may only be used for encryption. our signing key can be correctly seen with only the s.

note your new signing key’s id (the example shows a72db3ef on the second sub line above). your key’s id will be different.

enter save to return to the terminal and to save your new key.


detach master key from subkey

the point of creating the subkey is so we don’t need the master key on our server, which makes it more secure. now we’ll detach our master key from our subkey. we will need to export the master key and subkey, then delete the keys from gpg’s storage, then re-import just the subkey.

first let’s use the –export-secret-key and –export commands to export the whole key. remember to use your master key’s id!

gpg --export-secret-key 10e6133f > private.key
gpg --export 10e6133f >> private.key

by default –export-secret-key and –export will print the key to our console, so instead we pipe the output to a new file (private.key). make sure to specify your own master key id, as noted above.

important: make a copy of the private.key file somewhere safe (not on the server). possible locations are on a floppy disk or usb drive. this file contains your private key, your public key, your encryption subkey, and your signing subkey.

after you have backed up this file to a safe location, delete the file:

back up the private.key file before running this:

rm private.key

now export your public key and your subkey. make sure to change the ids to match the master key and the second subkey that you generated (don’t use the first subkey).

gpg --export 10e6133f > public.key
gpg --export-secret-subkeys a72db3ef > signing.key

now that we have a backup of our keys we can remove our master key from our server.

gpg --delete-secret-key 10e6133f

re-import only our signing subkey.

gpg --import public.key signing.key

check that we no longer have our master key on our server:

gpg --list-secret-keyssec#  4096r/10e6133f 2014-08-16
uid                  travis runyard <travis.runyard@example.com>
ssb   4096r/7b34e07c 2014-08-16
ssb   4096r/a72db3ef 2014-08-16

notice the # after sec. this means our master key is not installed. the server contains only our signing subkey.

clean up your keys:

rm public.key signing.key

the last thing you need to do is publish your signing key.

gpg --keyserver keyserver.ubuntu.com --send-key 10e6133f

this command publishes your key to a public storehouse of keys – in this case ubuntu’s own key server. this allows others to download your key and easily verify your packages.

set up a repository using reprepro

now let’s get to the point of this tutorial: creating an apt-get repository. apt-get repositories are not the easiest things to manage. thankfully r. bernhard created reprepro, who used to “produce, manage and sync a local repository of debian packages” (also known as mirrorer). reprepro is under the gnu licence and completely open source.

install and configure reprepro

reprepro can be installed from the default ubuntu repositories.

apt-get update
apt-get install reprepro

configuration for reprepro is repository-specific, meaning you can have different configurations if you make multiple repositories. let’s first make a home for our repository.

make a dedicated folder for this repository and move to it

mkdir -p /var/repositories/
cd /var/repositories/

create the configuration directory.

mkdir conf
cd conf/

create two empty config files (options and distributions).

touch options distributions

open up the options file in your favorite text editor (vi is installed by default but to get full functionality install vim).

vi options

this file contains options for reprepro and will be read every time reprepro runs. there are several options that you can specify here. see the manual for the other options.

in your text editor add the following by pressing the letter i


press escape then type :wq then hit enter. this will save our changes and return to the console.

the ask-passphrase directive tells reprepro to request a gpg password when signing. if we don’t add this to the options reprepro will die if our key is encrypted (it is).

open the distributions file.

vi distributions

this file has four required directives. add these to the file:

codename: xenial
components: main
architectures: i386 amd64
signwith: a72db3ef

the codename directive directly relates to the code name of the released debian distributions and is required. this is the code name for the distribution that will be downloading packages, and doesn’t necessarily have to match the distribution of this server. for example, the ubuntu 16.04 lts release is called xenial, ubuntu 14.04 lts is called trusty, ubuntu 12.04 lts is called precise, and debian 7.6 is known as wheezy. this repository is for ubuntu 16.04 lts so xenial should be set here.

the components field is required. this is only a simple repository so set main here. there are other namespaces such as “non−free” or “contrib” – refer to apt-get for proper naming schemes.

architectures is another required field. this field lists binary architectures within this repository separated by spaces. this repository will be hosting packages for 32-bit and 64-bit servers, so i386 amd64 is set here. add or remove architectures as you need them.

to specify how other computers will verify our packages we use the signwith directive. this is an optional directive, but required for signing. the signing key earlier in this example had the id a72db3ef, so that is set here. change this field to match the subkey’s id that you generated.

save and exit from the file by pressing escape then :wq and enter.

you have now set up the required structure for reprepro.

add a package(s) with reprepro

first let’s change our directory to a temporary location.

mkdir -p /tmp/debs
cd /tmp/debs

we need some example packages to work with – wget them with:

wget https://github.com/silvenga/examples/raw/master/example-helloworld_1.0.0.0_amd64.deb
wget https://github.com/silvenga/examples/raw/master/example-helloworld_1.0.0.0_i386.deb

these packages contain a simple bash script to prove the functionality of our repository. if you would prefer to simply move sync/copy all the .deb’s already cached on your computer use this command:

rsync -av /var/cache/apt/archives/ /tmp/debs/

running the program ls should give us this layout:

example-helloworld_1.0.0.0_amd64.deb  example-helloworld_1.0.0.0_i386.deb

we now have two example packages. one for 32-bit (i386) computers, another for 64-bit (amd64) computers. you can add them both to our repository with:

reprepro -b /var/repositories includedeb xenial example-helloworld_1.0.0.0_*

the -b argument specifies the “(b)ase” directory for the repository. the includedeb command requires two arguments – < distribution code name > and < file path(s) >. reprepro will prompt for our subkey passcode twice. if you want to specify all deb files in the directory, simply use *.deb.

exporting indices...
c3d099e3a72db3ef travis runyard <travis.runyard@example.com> needs a passphrase
please enter passphrase: < hidden >
c3d099e3a72db3ef travis runyard <travis.runyard@example.com> needs a passphrase
please enter passphrase: < hidden >

listing and deleting

we can list the managed packages with the list command followed by the codename. for example:

reprepro -b /var/repositories/ list xenial
xenial|main|i386: example-helloworld
xenial|main|amd64: example-helloworld

to delete a package, use the remove command. the remove command requires the codename of the package, and the package name. for example:

reprepro -b /var/repositories/ remove xenial example-helloworld

make the repository public

we now have a local package repository with a couple of packages. next, we’ll install nginx as a web server to make this repository available to your internal network.

install nginx

apt-get update
apt-get install nginx

nginx comes installed with a default example configuration. make a copy of the file in case you want to look at it at another time.

mv /etc/nginx/sites-available/default /etc/nginx/sites-available/default.bak
touch /etc/nginx/sites-available/default

now that we have an empty configuration file, we can start configuring our nginx server to host our new repository.

open the configuration file with your favorite text editor.

vi /etc/nginx/sites-available/default

and add the following configuration directives:

server {
listen 80 default_server;
listen [::]:80 default_server;
## let your repository be the root directory
root        /var/repositories;
## always good to log
access_log  /var/log/nginx/repo.access.log;
error_log   /var/log/nginx/repo.error.log;
location / {
index index.php index.html;
autoindex on;
## prevent access to reprepro's files
location ~ /(db|conf) {
deny        all;
return      404;

nginx has some pretty sane defaults. all we needed to configure was the root directory, while denying access to reprepro’s files. see the in-line comments for more details.

restart the nginx service to load these new configurations.

service nginx restart

or you can simply reload the configuration without restarting the daemon.

nginx –s reload

your public ubuntu repository is ready to use!

you’ll need your virtual machine’s ip address to let users know the location of the repository. if you don’t know your virtual machine’s public address you can find it with ifconfig.

ifconfig eth0
eth0      link encap:ethernet  hwaddr 04:01:23:f9:0e:01
inet addr:  bcast:  mask:
inet6 addr: fe80::601:23ff:fef9:e01/64 scope:link
up broadcast running multicast  mtu:1500  metric:1
rx packets:16555 errors:0 dropped:0 overruns:0 frame:0
tx packets:16815 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
rx bytes:7788170 (7.7 mb)  tx bytes:3058446 (3.0 mb)

in the above example, the server’s address is yours will be different.

with your reprepro server’s ip address, you can now add this repository to any other appropriate server.

install a package from our new repository

if you haven’t already, spin up another virtual machine with ubuntu 16.04 lts, so that you can do a test installation from your new repository.

on the new server, download your public key to verify the packages from your repository. recall that you published your key to keyserver.ubuntu.com.

this is done with the apt-key command.

apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 10e6133f

this command downloads the specified key and adds the key to the apt-get database. the adv command tells apt-key to use gpg to download the key. the other two arguments are passed directly to gpg. since you uploaded your key to “keyserver.ubuntu.com” use the –keyserver keyserver.ubuntu.com directive to retrived the key from the same location. the –recv-keys <key id> directive specifies the exact key to add.

now add the repository’s address for apt-get to find. you’ll need your repository server’s ip address from the previous step. this is easily done with the add-apt-repository program.

add-apt-repository "deb xenial main"

note the string that we give add-apt-repository. most debian repositories can be added with the following general format:

deb (repository location) (current distribution code name)  (the components name)

the repository location should be set to the location of your server. we have an http server so the protocol is http://. the example’s location was our server’s code name is xenial. this is a simple repository, so we called the component “main”. you can also simply append the text inside quotations at the end of the /etc/apt/sources.list file

after we add the repository, make sure to run an apt-get update. this command will check all the known repositories for updates and changes (including the one you just made).

apt-get update

after updating apt-get, you can now install the example package from your repository. use the apt-get command normally.

apt-get install example-helloworld

if everything is successful you can now execute example-helloworld and see:

hello, world!
this package was successfully installed!
congratulations! you have just installed a package from the repository that you created!

to remove the example package, run this command:

apt-get remove example-helloworld

this removes the example package that you just installed.

Disqus Comments Loading...

Recent Posts

FreeNAS Error Creating Pool

command '('gpart', 'create', '-s', 'gpt', '/dev/da8')' returned non-zero exit status 1. If you get this error while trying to create… Read More

May 14, 2019 8:22 am 08:22

Change Grub Default Boot Entry on Linux Mint

i'm dual booting windows and linux mint on my laptop. the grub default is to boot into linux mint, however… Read More

April 23, 2019 7:45 pm 19:45

How to Reset Secure Channel On Active Directory Domain Controller

when you're a little too careless about virtualizing your domain controllers, cloning, migrating, backing up and restoring, returning from vacation… Read More

April 21, 2019 8:14 am 08:14

Run SystemD Script Before System Shutdown

for the sheer hell of it, a few weeks ago i wanted to see if i could properly and successfully… Read More

April 20, 2019 10:14 am 10:14

Learn Systemctl Usage to Manage Systemd Service in Linux

systemd is new service manager for linux. it's a replacement for all previous init systems (sysv/sysvinit & ubuntu's upstart) and… Read More

April 20, 2019 7:55 am 07:55

Force Delete Windows Server DHCP Failover Relationship

if you've found yourself here then chances are you messed up one of your domain controllers or at least one… Read More

April 20, 2019 5:54 am 05:54