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 disable and enable hardware in Windows using command prompt

Sometimes bad driver of hardware load one or all cores of CPU by 100%. Some hardware has no other versions of driver and we must use bad driver.

Solution is – disable and enable hardware in Hardware manager. To do this automatic use script:

set HARDWARE_ID="PCI\VEN_8086&DEV_4229&SUBSYS_11018086&REV_61"
devcon disable %HARDWARE_ID%
timeout /t 3
devcon enable %HARDWARE_ID%

I created two files: Stop.bat and Start.bat. First stop bad device when Windows is shutting down, and the second start hardware when windows is starting. This solution help’s me and CPU no longer load by 100%

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

Node.js – Lesson 4: Deploy application on server using git, configure Nginx and pm2

To deploy Node.js application in Internet we need server and domain name. We will use Ubuntu 18.04. On server install Node.js using commands:

curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt-get install nodejs

Also we need to install Nginx web server to proxy http and https requests (from 80, 443 ports) to node application port.

sudo apt-get install nginx

We need to install Git if we want to deploy our application from git repository:

sudo apt-get install git

Next go to /home directory and use command:

git clone repositury_url

This command will clone all files from your git repository to server.

Next we need to install all dependencies from package.json:

npm install

And now we can run our application using command:

node index.js

But this command will stop work if our server will restart or if we close SSH connection to server. To run our application as daemon on server startm use special command pm2. Install it globally with Npm package manager:

sudo npm install pm2 -g

This program will run our node.js application in background:

pm2 start index.js

TO automatic start pm2 on system boot – generate startup script using command:

pm2 startup

And save configuration using command:

pm2 save

How to install Arch Linux with i3

1 .Download Arch Linux ISO from official site: https://www.archlinux.org/download/

2. Create Live USB of Arch Linux using Etcher GUI tool:

Etcher GUI tool on Linux

Or You can use Rufus in Windows:

Once you have created a liveUSB for Arch Linux, restart your PC and boot from USB. While booting press Delete, F2, F10 or F12 key to go into boot menu.

3. Create partition.

Use the command fdisk to show and create partitions on your system:

fdisk -l

If you have old partitions on your disk, you can delete them all using command:

wipefs -a /dev/sda

Be careful! This command destroy all data on your hard drive.

Select the disk you are going to partition:

fdisk /dev/sda

Enter n – to create new partition, then program ask you to choose a disk number, enter 1, and then enter first and last block of dist (press Enter for default).

4. Create root partition. To format root partition use command:

mkfs.ext4 /dev/sda1

5. Install Arch Linux

mount /dev/sda1 /mnt

Use pacstrap script to install all necessary packages:

pacstrap /mnt base linux linux-firmware vim nano mc

Generate a fstab file to define how disk partition, block devices or remote file systems are mounted into the filesystem.

genfstab -U /mnt >> /mnt/etc/fstab

Use arch-chroot and set the mounted disk as root. Now Arch Linux is installed on the disk.

arch-chroot /mnt

6. Setting up timezone

timedatectl list-timezones
timedatectl set-timezone Europe/Kiev

7. Setting up Locale

locale-gen
echo LANG=en_US.UTF-8 > /etc/locale.conf
export LANG=en_US.UTF-8

8. Network configuration

echo name > /etc/hostname
touch /etc/hosts

Node.js – Lesson 2: Start server, install dependencies

Next step of creating Node.js application is installing additional frameworks and dependencies that facilitate work with the project.

In our lesson we will use popular web framework “Express” and utility “Nodemon”, that will monitor for any changes in your source and automatically restart your server.

To install this dependencies in console write commands:

npm install express
npm install -D nodemon

Flag -D means that this is developer dependency and it not used in production project.

In section “scripts” write create script “start” and “dev”:

"start": "node index.js",
"dev": "nodemon index.js"