How to Install 2FAuth on Debian

2FAuth is a two-factor authentication server developed by Bubka. In this tutorial, we will guide you through the installation process of 2FAuth on Debian.

Requirements

Before you proceed with the installation, you need to have the following requirements:

Installing 2FAuth on Debian

To install 2FAuth on Debian, follow the steps below:

Step 1: Clone the 2FAuth Repository

First, clone the 2FAuth repository from Github using Git:

sudo apt-get install git 
git clone https://github.com/Bubka/2FAuth.git

Step 2: Install Composer

Navigate to the 2FAuth directory, and install Composer:

cd 2FAuth
sudo apt-get install composer

Step 3: Install Dependencies

Install the dependencies required by 2FAuth using Composer:

composer install

Step 4: Configure 2FAuth

Copy the .env.example file to a new .env file:

cp .env.example .env

Edit the .env file to configure your settings. For example, you can change the app name, database settings, and email settings.

nano .env

Step 5: Create a Database

Create a new database for 2FAuth, and grant privileges to the database user:

CREATE DATABASE 2fauth;
GRANT ALL PRIVILEGES ON 2fauth.* TO '2fauthuser'@'localhost' IDENTIFIED BY 'mypassword';
FLUSH PRIVILEGES;

Note: Replace 2fauthuser and mypassword with your own values.

Step 6: Run the Migration and Seeder

Run the migration and seeder to create and seed the database:

php artisan migrate --seed

Step 7: Generate a Key

Generate a new key for 2FAuth:

php artisan key:generate

Step 8: Create a Cron Job

Create a cron job to run the scheduled tasks:

crontab -e

Add the following line at the end:

* * * * * cd /path/to/2FAuth && php artisan schedule:run >> /dev/null 2>&1

Note: Replace /path/to/2FAuth with your own path.

Step 9: Configure the Web Server

Configure your web server to point to the public directory of 2FAuth:

Apache

Add the following VirtualHost configuration to /etc/apache2/sites-available/2FAuth.conf:

<VirtualHost *:80>
    ServerName yourdomain.com
    DocumentRoot /path/to/2FAuth/public
    <Directory /path/to/2FAuth/public>
        AllowOverride All
        Require all granted
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/2FAuth_error.log
    CustomLog ${APACHE_LOG_DIR}/2FAuth_access.log combined
</VirtualHost>

Enable the site and restart Apache:

sudo a2ensite 2FAuth.conf
sudo systemctl restart apache2

Nginx

Add the following server block configuration to /etc/nginx/sites-available/2FAuth:

server {
    server_name yourdomain.com;
    root /path/to/2FAuth/public;
    index index.php;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.4-fpm.sock;
    }

    location ~ /\.ht {
        deny all;
    }

    error_log /var/log/nginx/2FAuth_error.log;
    access_log /var/log/nginx/2FAuth_access.log;
}

Enable the site and restart Nginx:

sudo ln -s /etc/nginx/sites-available/2FAuth /etc/nginx/sites-enabled/
sudo systemctl restart nginx

Step 10: Access 2FAuth

Open your web browser, and go to http://yourdomain.com. You should see the 2FAuth login page. Enter the default username and password:

Username: admin
Password: password

You can change the default username and password later in the 2FAuth dashboard.

Conclusion

In this tutorial, you have learned how to install 2FAuth on Debian. With 2FAuth, you can add an extra layer of security to your web applications by requiring users to enter a one-time code generated by their mobile device.

If you want to self-host in an easy, hands free way, need an external IP address, or simply want your data in your own hands, give IPv6.rs a try!