Configure certificate in HestiaCP

1. Backup current certificates in directory /usr/local/hestia/ssl/:

mv /usr/local/hestia/ssl/certificate.crt /usr/local/hestia/ssl/certificate.crt.old 

mv /usr/local/hestia/ssl/certificate.key /usr/local/hestia/ssl/certificate.key.old 

2. In directory /usr/local/vesta/ssl/ make symbol links to certificates, that we use on our site (for example: site.com):

ln -s /home/admin/conf/web/site.com/ssl/site.com.crt /usr/local/hestia/ssl/certificate.crt 

ln -s /home/admin/conf/web/site.com/ssl/site.com.key /usr/local/hestia/ssl/certificate.key 

3. Restart Hestia service:

service hestia restart

How to exit vim? And other required commands.

Vim is the most popular Linux text editor, it was created in 1978 and is used to present days.

Vim has two modes: “Command mode” where you can insert many commands, and “Insert mode” – where you can insert and edit text document. By default Vim open all documents in “Command mode”, to enter into the “Insert mode” – press button “i“.

The most asked question is – “How to exit Vim?” – it is very simple – in Command mode enter :q! and press Enter. This command exit Vim without saving any changes.

:q!

To save file – enter command :w <filename> and press Enter:

:w file.txt

To save file and exit Vim use command :wq and press Enter

:wq

How to set permissions to files and folders in Linux terminal

There are there types of file permissions in Linux:

1. Owner permissions
2. Group permissions
3. Other permissions

Also you can set permissions for read, write and execute file for this three groups.

To set correct permissions for all files and folders in currend folder use command:

find . -type f -print0 | xargs -0 chmod 644
find . -type d -print0 | xargs -0 chmod 750

This commands will grant readm write, execute access for owner, read access for group and block all access for other users.

If you wand to grant access to files and folders for other users use commands:

find . -type f -print0 | xargs -0 chmod 665
find . -type d -print0 | xargs -0 chmod 751

Encrypt and decrypt files using GPG

To install GPG on your Debian/Ubuntu/Mint Linux operating system use command:

sudo apt-get install gpg

Default GPG folder is: /home/user/.gnupg. Generate private and public keys:

gpg --full-gen-key

Answer the several questions (encryption type: RSA, keysize: 4096 for better encryption, key expiration time, your name and email address) and press “O” if all changes are correct.

To view public keys use command:

gpg -k

To view secret gpg keys use command:

gpg -K

How to run custom file with Wine .exe in Linux Mint

To run Windows programs in Linux we use Wine. But how to open any file with exe program using Wine? For example we have 1.txt file. To run this file with notepad.exe use command:

wine "/home/user/notepad.exe" 1.txt

To associate some type of files with EXE program we can use shell script:

#!/bin/sh

QUICKPARLOCATION="/home/user/Notepad.exe"
PARAM=`winepath -w "$*" 2>/dev/null`
wine "$QUICKPARLOCATION" "$PARAM" &
exit 0

Put this file in /home/user/bin directory. Open file properties and in field “Open with” select Notepad.sh script:

How to install latest wine on Ubuntu or Linux Mint

The official WineHQ repository has a set of standard Wine packages that you can download and install on your system. Please follow these steps to do so:

Run the following command in the Terminal for adding i386 architecture before installing a 64-bit version of Wine:

sudo dpkg --add-architecture i386
Next add the WineHQ signing key:

wget -qO- https://dl.winehq.org/wine-builds/Release.key | sudo apt-key add -

Then run this command to import the other key for the WineHQ Repository:

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv F987672F

Now run the following command in order to add the relevant repository from the WineHQ:

sudo apt-add-repository 'deb https://dl.winehq.org/wine-builds/ubuntu/ bionic main'

Next update the Ubuntu package lists with the command:

sudo apt-get update

Now we can install latest stable version of Wine in Ubuntu or Linux Mint operating system:

sudo apt-get install --install-recommends winehq-stable

Linux how to fix ext4 filesystem

Sometimes if server is shutdown incorrect filesystem filesystem can be corrupted and loaded in “read only” mode.

To check file system status use command:

mount | grep /dev/sd

This command show filesystem status, if filesystem is read only – you will see “ro” status: /dev/sda2 on / type ext4 (ro,readonly,data=ordered)

To fix filesystem use command:

fsck /dev/sda2

This command will fix all errors on filesystem, To apply fix enter y on keybord. When fixing is complete reboot system and check filesystem again.

How to get SMNP information from router using PHP

First install SNMP package:

sudo apt-get install snmp

To use SNMP in PHP install php-snmp extention:

sudo apt-get install -y php-snmp

Get SNMP information from router user command:

snmpwalk -v2c -Cc -c public 192.168.1.1 > out.txt

This command will get all SNMP information from router 192.168.1.1 and save it into file out.txt

Now let’s create file index.php and write code that will get all MAC addresses from BDCOM P3310 OLT. To get all MAC addresses use OID: iso.3.6.1.2.1.17.7.1.2.2.1.1. In PHP file create function SnmpGet:

function SnmpGet($host, $community, $object_id){
    exec("snmpwalk  -v2c -Cc -c ".$community." ".$host." ".$object_id, $snmpWalkReturn);
    foreach($snmpWalkReturn as $value){
            $oid = explode("=", $value);
            $walk[trim($oid[0])] = trim($oid[1]);
    }
    return $walk;
}

Put SNMP result in variable $MacResult:

$MacResult = snmprealwalk2($hostname, $community, "iso.3.6.1.2.1.17.7.1.2.2.1.1");

In cycle foreach go through all elements and remove unnecessary data:

if(count($MacResult)){
    foreach($MacResult as $Item => $Value)
    {
        $Oid = str_replace("iso.3.6.1.2.1.17.7.1.2.2.1.1.", "", $Item);
        $Mac = str_replace("Hex-STRING: ", "", $Value);

        if(!strpos($Mac, "STRING:")){
            echo $Mac.' | '.$Oid;
        }
    }
}

Similarly get EPON interface id from OID: iso.3.6.1.2.1.17.7.1.2.2.1.2