How to use the command `pivpn` (with examples)

How to use the command `pivpn` (with examples)

The pivpn command is a tool that simplifies the process of setting up and managing an OpenVPN server. Originally designed for the Raspberry Pi, it can also be used on other Linux devices. It provides an easy and secure way to create a VPN (Virtual Private Network) to protect your online communications and enhance your privacy.

Use case 1: Adding a new client device

To add a new client device to the VPN server, you can use the following command:

sudo pivpn add

Motivation: Adding a new client device allows you to grant secure access to the VPN server for a new device. This is useful when you have multiple devices that need to connect to the VPN.

Explanation: The sudo pivpn add command is used to add a new client profile to the OpenVPN server. It will prompt you to enter a name for the client and generate a new certificate and configuration file for that client.

Example output:

Enter a name for the client: my-laptop
...
Done! my-laptop.ovpn successfully created.

Use case 2: Listing all client devices

To list all the client devices that have been added to the VPN server, you can use the following command:

sudo pivpn list

Motivation: Listing all the client devices allows you to see the current clients connected to the VPN server. It helps you keep track of who has access to the server.

Explanation: The sudo pivpn list command provides a list of all the client profiles that have been created on the OpenVPN server. It displays the names of the clients along with their associated configuration files.

Example output:

my-laptop
my-phone
my-tablet

Use case 3: Listing currently connected devices and their statistics

To view the currently connected client devices and their statistics, you can use the following command:

sudo pivpn clients

Motivation: Monitoring the currently connected devices and their statistics gives you insights into the usage and performance of the VPN server. It helps you identify any potential issues and optimize the server configuration.

Explanation: The sudo pivpn clients command provides a list of all the client devices that are currently connected to the OpenVPN server. It displays information such as the client name, remote IP address, bytes sent and received, connection duration, and the timestamp of the last activity.

Example output:

Client                    Remote IP               Sent      Received   Last Seen
------------------------  ----------------------  --------- ---------  -------------------
my-laptop                 192.168.1.100           1.23 GB   456.78 MB  2022-01-01 10:00:00
my-phone                  192.168.1.101           876 MB    123 MB     2022-01-01 09:30:00
my-tablet                 192.168.1.102           234 MB    876 KB     2022-01-01 09:15:00

Use case 4: Revoking a previously authenticated device

To revoke access for a previously authenticated device, you can use the following command:

sudo pivpn revoke

Motivation: Revoking access for a device is necessary when a device is lost, stolen, or no longer authorized to connect to the VPN server. It helps maintain the security and integrity of the VPN network.

Explanation: The sudo pivpn revoke command is used to revoke the client certificate and configuration file for a specific device. It will prompt you to select the device from a list of available clients and revoke its access.

Example output:

Which client would you like to revoke?
1) my-laptop
2) my-phone
3) my-tablet
#? 2
...
Done! Client my-phone revoked.

Use case 5: Uninstalling PiVPN

To uninstall PiVPN from your system, you can use the following command:

sudo pivpn uninstall

Motivation: Uninstalling PiVPN may be necessary if you no longer need the VPN server or want to free up system resources. It allows you to cleanly remove PiVPN from your Linux device.

Explanation: The sudo pivpn uninstall command removes all the PiVPN files, including the OpenVPN server and its associated configurations. It will prompt you to confirm the uninstallation.

Example output:

Are you sure you want to uninstall PiVPN?
(Are you sure? Must be typed to proceed): yes
...
Uninstall completed successfully.

Conclusion:

In this article, we have explored several examples of using the pivpn command. We have learned how to add a new client device, list all client devices, list currently connected devices and their statistics, revoke a previously authenticated device, and uninstall PiVPN. These examples demonstrate the versatility and ease of use provided by the pivpn tool, making it an excellent choice for setting up and managing an OpenVPN server.

Related Posts

New-Item (with examples)

New-Item (with examples)

Create a new blank file (equivalent to touch): Code: New-Item C:\path\to\file.

Read More
How to use the command 'yank' (with examples)

How to use the command 'yank' (with examples)

The ‘yank’ command is a utility tool that allows the user to select specific fields from input data and copy them to the clipboard.

Read More
How to use the command 'resume' (with examples)

How to use the command 'resume' (with examples)

The resume command is a powerful tool for easily setting up a new resume.

Read More