Category: Linux

  • Set vim as default cronjob editor

    Method 1

    vi /etc/bashrc
    

    Find

    export EDITOR="pico"
    export VISUAL="pico"
    

    Replace with

    export EDITOR="vi"
    export VISUAL="vi"
    

    Method 2

    edit .bash_profile

    vi /root/.bash_profile
    

    Add

    export VISUAL=vi
    

    Once added, .bash_profile will look like

    root@server54 [~]# cat .bash_profile
    # .bash_profile
    
    # Get the aliases and functions
    if [ -f ~/.bashrc ]; then
            . ~/.bashrc
    fi
    
    # User specific environment and startup programs
    
    PATH=$PATH:$HOME/bin
    
    export VISUAL=vi
    export PATH
    unset USERNAME
    uptime
    root@server54 [~]#
    

    Method 3

    If you need it done one time only, run following commands on command prompt.

    VISUAL=vi; export VISUAL
    
  • xdotool

    xdotool lets you programmatically simulate keyboard input and mouse activity, move and resize windows, etc.

    To search for an application with title name, run

    xdotool search --name TEXT_TO_SERCH_HERE
    

    This will return ID of the windows. You can use xwininfo command to view information about the application window.

    Example

    boby@hon-pc-01:~ $ xdotool search --name RuneScape
    77594631
    boby@hon-pc-01:~ $ xwininfo -id 77594631
    
    xwininfo: Window id: 0x4a00007 "RuneScape"
    
      Absolute upper-left X:  65
      Absolute upper-left Y:  24
      Relative upper-left X:  0
      Relative upper-left Y:  0
      Width: 1855
      Height: 1056
      Depth: 24
      Visual: 0x21
      Visual Class: TrueColor
      Border width: 0
      Class: InputOutput
      Colormap: 0x20 (installed)
      Bit Gravity State: NorthWestGravity
      Window Gravity State: NorthWestGravity
      Backing Store State: NotUseful
      Save Under State: no
      Map State: IsViewable
      Override Redirect State: no
      Corners:  +65+24  -0+24  -0-0  +65-0
      -geometry 1855x1056-0-0
    
    boby@hon-pc-01:~ $ 
    
  • brctl

    brctl show

    [root@server70 etc]# brctl show
    bridge name     bridge id               STP enabled     interfaces
    br0             8000.002590d08d66       no              eth0
                                                            vnet0
    virbr0          8000.525400f12faf       yes             virbr0-nic
    [root@server70 etc]# ifconfig
    br0       Link encap:Ethernet  HWaddr 00:25:90:D0:8D:66
              inet addr:192.99.18.195  Bcast:192.99.18.255  Mask:255.255.255.0
              inet6 addr: fe80::225:90ff:fed0:8d66/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:8108397 errors:0 dropped:0 overruns:0 frame:0
              TX packets:7823258 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:0
              RX bytes:1951542690 (1.8 GiB)  TX bytes:15136345174 (14.0 GiB)
    
    br0:1     Link encap:Ethernet  HWaddr 00:25:90:D0:8D:66
              inet addr:198.27.105.228  Bcast:198.27.105.228  Mask:255.255.255.255
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
    
    eth0      Link encap:Ethernet  HWaddr 00:25:90:D0:8D:66
              inet6 addr: fe80::225:90ff:fed0:8d66/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:69612987 errors:6 dropped:0 overruns:0 frame:6
              TX packets:114006505 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000
              RX bytes:7042298846 (6.5 GiB)  TX bytes:151793078797 (141.3 GiB)
              Interrupt:48 Memory:fe9e0000-fea00000
    
    lo        Link encap:Local Loopback
              inet addr:127.0.0.1  Mask:255.0.0.0
              inet6 addr: ::1/128 Scope:Host
              UP LOOPBACK RUNNING  MTU:16436  Metric:1
              RX packets:407995 errors:0 dropped:0 overruns:0 frame:0
              TX packets:407995 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:0
              RX bytes:1284505268 (1.1 GiB)  TX bytes:1284505268 (1.1 GiB)
    
    virbr0    Link encap:Ethernet  HWaddr 52:54:00:F1:2F:AF
              inet addr:192.168.122.1  Bcast:192.168.122.255  Mask:255.255.255.0
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:0 errors:0 dropped:0 overruns:0 frame:0
              TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:0
              RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)
    
    vnet0     Link encap:Ethernet  HWaddr FE:54:00:F6:41:4B
              inet6 addr: fe80::fc54:ff:fef6:414b/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:44 errors:0 dropped:0 overruns:0 frame:0
              TX packets:24993 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:500
              RX bytes:3499 (3.4 KiB)  TX bytes:2333834 (2.2 MiB)
    
    [root@server70 etc]#
    

    brctl showmacs br0

    [root@server70 etc]#  brctl showmacs br0
    port no mac addr                is local?       ageing timer
      1     00:05:73:a0:00:00       no                11.10
      1     00:07:b4:00:00:02       no                 2.72
      1     00:07:b4:00:01:01       no                 4.73
      1     00:07:b4:00:01:02       no                 6.65
      1     00:25:90:7b:a3:8e       no                31.80
      1     00:25:90:7c:72:34       no                53.08
      1     00:25:90:d0:8d:66       yes                0.00
      1     00:2a:6a:3d:50:81       no               119.90
      1     00:2a:6a:3d:df:bc       no                 2.33
      1     c8:f9:f9:58:3f:c0       no                 0.00
      1     d8:24:bd:91:c7:00       no                 0.00
      2     fe:54:00:f6:41:4b       yes                0.00
    [root@server70 etc]#
    

    brctl showstp br0

    [root@server70 etc]# brctl showstp br0
    br0
     bridge id              8000.002590d08d66
     designated root        8000.002590d08d66
     root port                 0                    path cost                  0
     max age                  19.99                 bridge max age            19.99
     hello time                1.99                 bridge hello time          1.99
     forward delay            14.99                 bridge forward delay      14.99
     ageing time             299.95
     hello timer               0.42                 tcn timer                  0.00
     topology change timer     0.00                 gc timer                   8.42
     hash elasticity           4                    hash max                 512
     mc last member count      2                    mc init query count        2
     mc router                 1                    mc snooping                1
     mc last member timer      0.99                 mc membership timer      259.96
     mc querier timer        254.96                 mc query interval        124.98
     mc response interval      9.99                 mc init query interval    31.24
     flags
    
    
    eth0 (0)
     port id                0000                    state                forwarding
     designated root        8000.002590d08d66       path cost                  4
     designated bridge      8000.002590d08d66       message age timer          0.00
     designated port        8001                    forward delay timer        0.00
     designated cost           0                    hold timer                 0.00
     mc router                 1
     flags
    
    vnet0 (0)
     port id                0000                    state                forwarding
     designated root        8000.002590d08d66       path cost                100
     designated bridge      8000.002590d08d66       message age timer          0.00
     designated port        8002                    forward delay timer        0.00
     designated cost           0                    hold timer                 0.00
     mc router                 1
     flags
    
    [root@server70 etc]#
    
  • Change Apache User in Ubuntu

    On Ubuntu/Debian server, apache run as user www-data. When you install Apache web server on your local computer for developement purpose, it may be easier to run Apache as your user. If you run Apache as www-data user, you will need to chmod folders 777 for yoru web application to write to a folder like file upload, creating log files etc..

    To change Apache user, edit file

    vi /etc/apache2/envvars
    

    Find and replace www-data with your user name. You can do this with following sed command

    sed -i "s/www-data/USERNAME/g" /etc/apache2/envvars
    chown -R USERNAME:USERNAME /var/lib/php
    
  • Block Country in CSF firewall

    CSF firewall can block all traffic from a country or list of countries using the GeoIP database.

    To block a country, edit the file

    /etc/csf/csf.conf
    

    Find

    CC_DENY=""
    

    Replace with

    CC_DENY="2_LETTER_COUNTRY_CODE"
    

    Here is an example to block all traffic from China

    CC_DENY="CN"
    

    If you want to block another country, you can add it like

    CC_DENY="CN,RU"
    

    Now restart CSF firewall with

    csf -r
    

    See CSF firewall

  • zpool

    zpool is tool to manage ZFS file system. Here are some zpool commands

    zpool list
    zpool list rpool
    zpool list tank
    zpool status
    zpool status -v rpool
    zpool status -v tank
    zpool status -x
    zpool iostat
    
  • Install wireguard VPN on Ubuntu

    To install wireguard VPN on ubuntu, run

    apt update
    apt install software-properties-common
    apt install linux-headers-$(uname -r)
    add-apt-repository ppa:wireguard/wireguard
    apt-get update
    apt-get install wireguard
    

    Generate Keys

    cd /etc/wireguard
    umask 077
    wg genkey > privatekey
    cat privatekey | wg pubkey > publickey
    

    Configure wireguard

    You can generate wireguard configuration using

    https://www.wireguardconfig.com

  • Install Perl Modules Using CPAN

    Comprehensive Perl Archive Network (CPAN) is a directory of Perl modules. To install a perl module, run

    cpan
    

    In the cpan command prompt, you can type

    install MODUE_NAME
    

    Example

    install Term::ReadKey
    

    You can also use

    cpan install Term::ReadKey
    

    List instaled CPAN modules

    cpan -l
    
  • Load balancer

    Load Balancer is used to distribute incoming traffic to multiple backend servers.

    Here are some of the popular software load balancers

    https://nginx.org/

    http://www.haproxy.org/

    https://containo.us/traefik/

  • CentovaCast change MySQL password

    CentovaCast is a control panel to manage online streaming services. It support shoucast, liqudsoap and icecast streaming servers.

    To change MySQL Password in CentovaCast, update following files.

    /usr/local/centovacast/etc/centovacast.conf
    

    You will see something like

    # Enter your database connection information.
    DB_NAME=centovacastdb
    DB_USER=centovacast
    DB_PASS=MySQLPasswordHere
    DB_HOST=localhost
    

    Following files is auto generated, this file also contain MySQL login details

    /usr/local/centovacast/system/autoconfig.php
    

    See CentovaCast