[Debian 7] How to install ZNC on Debian 7

How to install the ZNC IRC bouncer on your Debian 7 server
by puffrfish

ZNC is a popular IRC bouncer software. You can use ZNC to appear as though you are always connected to an IRC network and ZNC will keep a scrollback of things that have been said while you were gone.

Prerequisites

This tutorial assumes you've already done the initial setup for your server. There are a few additional items we should check before beginning the installation of ZNC.

Install ntp

While not required, installing ntp makes sure the time on your server is correct. This is important for ZNC to give you correct timestamps, as well as to make sure the SSL configuration works properly.

fish@shellfish:~$ sudo apt-get update
fish@shellfish:~$ sudo apt-get install ntp

Setting the time zone

Setting the time zone makes sure your timestamps in your scrollback on ZNC are in the right timezone.

fish@shellfish:~$ sudo dpkg-reconfigure tzdata

Select the timezone you want your server to be in. You are able to offset this in the ZNC web configuration panel if needed.

Logging in as root

It is much easier to go through this tutorial while logged into the root account. To do this, issue the following command and type your own account password when prompted.

fish@shellfish:~$ sudo -i

From now on in the tutorial, I'll assume you're logged in as the root user

Install the required packages to compile ZNC

These packages are needed to compile ZNC from source.

root@shellfish:~# apt-get install build-essential
root@shellfish:~# apt-get install libssl-dev
root@shellfish:~# apt-get install libperl-dev

Compiling and installing ZNC

Downloading and extracting the source

First we'll make sure we're in our home directory for the root user.

root@shellfish:~# cd ~

Now we'll download the ZNC source

root@shellfish:~# wget http://znc.in/releases/znc-latest.tar.gz

We need to extract the source from the archive with this command

root@shellfish:~# tar -xzf znc-latest.tar.gz

Navigate inside the newly created directory

root@shellfish:~# cd znc-*

Compiling the source

Now we'll run the pre-compilation configuration script

root@shellfish:~# ./configure --with-openssl

You can now compile the program by running

root@shellfish:~# make

After it has compiled run

root@shellfish:~# make install

Installing the ZNC service script

This script allows us to run ZNC as a service. The following command will download the script and place it into the right directory.

root@shellfish:~# wget -O /etc/init.d/znc https://shellfish.io/_file/1/1/znc

Now we need to make the script executable and make sure ZNC starts up at boot.

root@shellfish:~# chmod +x /etc/init.d/znc
root@shellfish:~# update-rc.d znc defaults

Creating the ZNC user

ZNC should never be run as root, so we're going to create a special user for ZNC to run under.

root@shellfish:~# useradd -m -s /bin/bash -d /var/lib/znc znc

Now we can login as the znc user by issuing

root@shellfish:~# su znc

Change into the znc user's home directory

znc@shellfish:/root$ cd ~

Configuring ZNC

Now we can go through the ZNC configuration script.

znc@shellfish:~$ znc -d /var/lib/znc --makeconf
[ ok ] Checking for list of available modules...
[ ** ] Building new config
[ ** ]
[ ** ] First let's start with some global settings...
[ ** ]
[ ?? ] What port would you like ZNC to listen on? (1025 to 65535): 1337
[ ?? ] Would you like ZNC to listen using SSL? (yes/no) [no]: yes
[ ** ] Unable to locate pem file: [/var/lib/znc/znc.pem]
[ ?? ] Would you like to create a new pem file now? (yes/no) [yes]: yes
[ ok ] Writing Pem file [/var/lib/znc/znc.pem]...
[ ?? ] Would you like ZNC to listen using ipv6? (yes/no) [yes]: yes
[ ?? ] Listen Host (Blank for all ips):
[ ok ] Verifying the listener...
[ ** ]
[ ** ] -- Global Modules --
[ ** ]
[ ** ] +-----------+----------------------------------------------------------+
[ ** ] | Name      | Description                                              |
[ ** ] +-----------+----------------------------------------------------------+
[ ** ] | partyline | Internal channels and queries for users connected to znc |
[ ** ] | webadmin  | Web based administration module                          |
[ ** ] +-----------+----------------------------------------------------------+
[ ** ] And 9 other (uncommon) modules. You can enable those later.
[ ** ]
[ ?? ] Load global module <partyline>? (yes/no) [no]: no
[ ?? ] Load global module <webadmin>? (yes/no) [no]: yes
[ ** ]
[ ** ] Now we need to set up a user...
[ ** ]
[ ?? ] Username (AlphaNumeric): zncuser
[ ?? ] Enter Password:
[ ?? ] Confirm Password:
[ ?? ] Would you like this user to be an admin? (yes/no) [yes]: yes
[ ?? ] Nick [zncuser]: zncuser
[ ?? ] Alt Nick [zncuser_]:
[ ?? ] Ident [zncuser]:
[ ?? ] Real Name [Got ZNC?]:
[ ?? ] Bind Host (optional):
[ ?? ] Number of lines to buffer per channel [50]:
[ ?? ] Would you like to clear channel buffers after replay? (yes/no) [yes]:
[ ?? ] Default channel modes [+stn]:
[ ** ]
[ ** ] -- User Modules --
[ ** ]
[ ** ] +--------------+------------------------------------------------------------------------------------------+
[ ** ] | Name         | Description                                                                              |
[ ** ] +--------------+------------------------------------------------------------------------------------------+
[ ** ] | chansaver    | Keep config up-to-date when user joins/parts                                             |
[ ** ] | controlpanel | Dynamic configuration through IRC. Allows editing only yourself if you're not ZNC admin. |
[ ** ] | perform      | Keeps a list of commands to be executed when ZNC connects to IRC.                        |
[ ** ] +--------------+------------------------------------------------------------------------------------------+
[ ** ] And 22 other (uncommon) modules. You can enable those later.
[ ** ]
[ ?? ] Load module <chansaver>? (yes/no) [no]: yes
[ ?? ] Load module <controlpanel>? (yes/no) [no]:
[ ?? ] Load module <perform>? (yes/no) [no]:
[ ** ]
[ ?? ] Would you like to set up a network? (yes/no) [no]:
[ ** ]
[ ?? ] Would you like to set up another user? (yes/no) [no]:
[ ok ] Writing config [/var/lib/znc/configs/znc.conf]...
[ ** ]
[ ** ] To connect to this ZNC you need to connect to it as your IRC server
[ ** ] using the port that you supplied.  You have to supply your login info
[ ** ] as the IRC server password like this: user/network:pass.
[ ** ]
[ ** ] Try something like this in your IRC client...
[ ** ] /server <znc_server_ip> +1337 zncuser:<pass>
[ ** ] And this in your browser...
[ ** ] https://<znc_server_ip>:1337/
[ ** ]
[ ?? ] Launch ZNC now? (yes/no) [yes]: no

Now you can exit the znc user

znc@shellfish:~$ exit

You can now start ZNC by typing

root@shellfish:~# service znc start