Category: Linux

  • List all files in an rpm package

    To list all files in an rpm package run

    rpm -ql PACKAGE_NAME
    
  • Install OpenVPN Access Server

    OpenVPN Access Server is paid version of OpenVPN with easy to use control panel. You can see license pricing at

    https://openvpn.net/access-server/pricing/

    First 2 users/devices are free to use. To install download the software from

    https://openvpn.net/download-open-vpn/

    On this page, you will see downloads for various operating systems.

    Install on CentOS 7

    To install on CentOS 7, run

    wget https://openvpn.net/downloads/openvpn-as-latest-CentOS7.x86_64.rpm
    rpm -ivh openvpn-as-latest-CentOS7.x86_64.rpm
    

    Example

    [root@localhost ~]# rpm -ivh openvpn-as-latest-CentOS7.x86_64.rpm 
    Preparing...                          ################################# [100%]
    Updating / installing...
       1:openvpn-as-0:2.7.4_777bcfe6-CentO################################# [100%]
    
    The Access Server has been successfully installed in /usr/local/openvpn_as
    Configuration log file has been written to /usr/local/openvpn_as/init.log
    
    Please enter "passwd openvpn" to set the initial
    administrative password, then login as "openvpn" to continue
    configuration here: https://158.69.103.158:943/admin
    
    To reconfigure manually, use the /usr/local/openvpn_as/bin/ovpn-init tool.
    
    +++++++++++++++++++++++++++++++++++++++++++++++
    Access Server Web UIs are available here:
    Admin  UI: https://158.69.103.158:943/admin
    Client UI: https://158.69.103.158:943/
    +++++++++++++++++++++++++++++++++++++++++++++++
    
    Beginning with OpenVPN AS 2.6.0 compression is disabled by default and on upgrades as security patch.
    [root@localhost ~]# 
    

    You can set the password for the system user “openvpn” to access the OpenVPN control panel.

    Install on Debian 9

    apt install -y net-tools
    wget https://openvpn.net/downloads/openvpn-as-latest-debian9.amd_64.deb
    dpkg -i openvpn-as-latest-debian9.amd_64.deb
    

    You need to open the following ports on the firewall for OpenVPN to work.

    443/tcp
    943/tcp
    1194/udp
    

    See VPN

  • awk

    cut
    How to cut lines separated by multiple spaces?
    How to get list of User-Agent from access log

    To list all kernels available in your server, run

    awk -F\' '$1=="menuentry " {print i++ " =  "$2}' /etc/grub2.cfg
    

    Example

    root@server48 [~]# awk -F\' '$1=="menuentry " {print i++ " =  "$2}' /etc/grub2.cfg
    0 =  CloudLinux (3.10.0-962.3.2.lve1.5.24.10.el7.x86_64) 7.6 (Vladimir Lyakhov)
    1 =  CloudLinux (3.10.0-962.3.2.lve1.5.24.9.el7.x86_64) 7.6 (Vladimir Lyakhov)
    2 =  CloudLinux (3.10.0-962.3.2.lve1.5.24.8.el7.x86_64) 7.6 (Vladimir Lyakhov)
    3 =  CloudLinux (3.10.0-962.3.2.lve1.5.24.5.el7.x86_64) 7.5 (Viktor Gorbatko)
    4 =  CloudLinux (3.10.0-962.3.2.lve1.5.24.4.el7.x86_64) 7.5 (Viktor Gorbatko)
    root@server48 [~]#
    

    To print all users from /etc/passwd, run

    cat /etc/passwd | awk -F: '{print $1}'
    

    To list all file names from ls -l command, run

    ls -l | awk -F' ' '{print $9}'
    
  • Upgrade Debian 8 Jessie To Debian 9 Stretch

    Upgrade Debian 8 Jessie To Debian 9 Stretch

    debian linux

    Upgrading server on a remote location is not safe unless you have KVM access. I did many Debian 8 to Debian 9 upgrade on remote server with out probem. On one server, network card name chaned from eth0 to new enp4s0 format. I had to access the server using KVM and fix network configuration by editing /etc/network/interfaces

    First you need to upgrade all software on your server to latest Debian 8

    apt update && apt upgrade -y && apt dist-upgrade -y
    

    Now replace content of /etc/apt/sources.list file with following

    vi /etc/apt/sources.list
    

    Add

    deb http://cloudfront.debian.net/debian/ stretch main non-free contrib
    deb-src http://cloudfront.debian.net/debian/ stretch main non-free contrib
    
    deb http://security.debian.org/debian-security stretch/updates main contrib non-free
    deb-src http://security.debian.org/debian-security stretch/updates main contrib non-free
    

    Update the software again with

    apt update && apt upgrade -y && apt dist-upgrade -y
    

    It can take some time for the upgrade to finish. Once update complete, you can check with lsb_release -a command, you will see

    debian upgrade

    Remove unused packages with command

    apt autoremove -y
    

    At this stage, server stil use old debian 8 kernal.

    root@v2m2:~# uname -r
    3.16.0-6-amd64
    root@v2m2:~# 
    

    To boot to new Debian 9 kernal, reboot the server with

    reboot
    

    After reboot, you will see new kernal.

    Now Debian 10 is available. See How to upgrade Debian 9 to Debian 10

  • Install Skype on Ubuntu

    Install Skype on Ubuntu

    Skype public key is not available

    To install Skype on Ubuntu 20.04 (this work with other Ubuntu/Debian versions), run

    curl https://repo.skype.com/data/SKYPE-GPG-KEY | sudo apt-key add -
    echo "deb [arch=amd64] https://repo.skype.com/deb stable main" | sudo tee /etc/apt/sources.list.d/skype-stable.list
    sudo apt-get update
    sudo apt-get install apt-transport-https -y
    sudo apt-get install skypeforlinux -y
    

    Skype Commands

    https://support.skype.com/faq/FA10042/What-are-chat-commands-and-roles

    To disable alerts from a skype chat group, enter

    /alertsoff	Disable message alert notifications.
    /alertson [text]	Allows you to specify exactly what needs to appear in a chat for the chat to pop up. For example, your name.
    
  • Manage Linux Software Raid with mdadm

    To assemble a software raid, run

    mdadm --assemble /dev/md0  /dev/sda1 /dev/sdb1

    Auto assemble

    mdadm --assemble --scan

    Get details about the raid

    mdadm --detail --scan
  • bluetooth

    To list bluetooth devices on Ubuntu, run

    hcitool  dev
    

    To list usb devices, run

    boby@sok-01:~$ lsusb
    Bus 006 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
    Bus 005 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
    Bus 003 Device 004: ID 0cf3:9271 Atheros Communications, Inc. AR9271 802.11n
    Bus 003 Device 003: ID 2516:0057  
    Bus 003 Device 002: ID 046d:c077 Logitech, Inc. M105 Optical Mouse
    Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
    Bus 001 Device 003: ID 1395:0025 Sennheiser Communications 
    Bus 001 Device 002: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode)
    Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    boby@sok-01:~$ 
    

    “Cambridge Silicon Radio” is the USB device i have on my PC.

  • fuser

    To instal fuser on CentOS 7, run

    yum install psmisc -y
    

    To see which program use a port, run

    fuser 80/tcp
    

    To kill process running in TCP Port 80

    fuser -k 80/tcp
    

    Example

    boby@sok-01:~$ fuser -k 8000/tcp
    8000/tcp:            25333
    boby@sok-01:~$
    
  • umount /home device is busy

    I wanted to unmount /home drive on a server.

    If any program is accessing the drive, you won’t be able to unmount the disk. You need stop stop all process that use the drive.

    To find the programs that use the /home partition, run

    lsof /home
    

    Or

    fuser -mv /home
    

    This list all process, stop the process or kill it. Now you should be able to unmount the partition with

    umount /home
    
  • Run a script on boot using systemd on Ubuntu 18.04

    Previous versions of Ubuntu had /etc/rc.local. that get executed after system boot.

    On Ubuntu 18.04, you can use systemd to start a bash script on system boot.

    Create file

    vi /etc/systemd/system/sok-startup.service
    

    Add

    [Unit]
    Description=Start up script
    ConditionPathExists=/etc/rc.local
    
    [Service]
    Type=forking
    ExecStart=/etc/rc.local start
    TimeoutSec=0
    StandardOutput=tty
    RemainAfterExit=yes
    SysVStartPriority=99
    
    [Install]
    WantedBy=multi-user.target
    

    Create file /etc/rc.local with

    #!/bin/bash
    
    touch /root/OK
    
    exit 0
    

    You can replace “touch /root/OK” with whatever command you need to execute.

    Make it executable with

    chmod 755 /etc/rc.local
    

    Reload systemd

    systemctl daemon-reload
    

    Enable the service

    systemctl enable sok-startup.service
    

    Now reboot the server, you will see /root/OK get created.

  • Find all live hosts on your network

    nmap can be used to get list of all devices on your network.

    To scan IP range 192.168.1.1 to 192.168.1.255, run

    nmap -sP 192.168.1.1-255
    

    You can also use CIDR notation like

    nmap -sP 192.168.1.0/24
    

    nmap

    You can also use

    -sL: List Scan - simply list targets to scan
    -sn: Ping Scan - disable port scan
    

    To idenify the host OS and check if ports 80 and 8080 open, run

    sudo nmap -sS -O -p80,8080 192.168.1.1-255