Category: Linux

  • Redirect OLD site to NEW using htaccess

    To redirect old site to new url using .htacces, use following

    RewriteCond %{HTTP_HOST} ^old-url.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www.old-url.com$
    RewriteRule (.*)$ http://www.new-url.com/$1 [R=301,L]
    

    See htaccess

  • List kernel modules

    To list kernal modules, use

    lsmod
    

    Example

    boby@sok-01:~$ lsmod | grep rtl
    rtl8xxxu              122880  0
    mac80211              778240  2 ath9k_htc,rtl8xxxu
    boby@sok-01:~$ 
    
  • Install mitmproxy on Ubuntu

    Install mitmproxy on Ubuntu

    mitmproxy is a man in the middle proxy server for debugging.

    mitmproxy

    To install mitmproxy on Ubuntu, run

    sudo apt install mitmproxy -y
    

    On Ubuntu 18.04, this is broken. To insall i created a virtualenv

    mkdir -p  ~/www/mitmproxy
    cd ~/www/mitmproxy
    virtualenv --python=/usr/bin/python3 venv
    source venv/bin/activate
    

    Install mitmproxy inside virtualenv with

    pip install mitmproxy
    

    To start, run

    mithproxy
    

    This will listen proxy on port 8080, you can verify with command

    netstat -lntp
    

    If you get error like

    boby@sok-01:~$ /home/boby/www/mitmproxy/venv/bin/mitmproxy
    Error: mitmproxy requires a UTF console environment.
    Set your LANG environment variable to something like en_US.UTF-8
    boby@sok-01:~$ 
    

    Run

    export LANG=en_US.UTF-8
    mitmproxy
    

    To configure in browser, you can use it as HTTP proxy. Here is how i configure it on Firefox FoxyProxy.

  • Logging Linux Commands for all users

    To log commands executed by users on Linux shell, edit file

    vi /etc/bash.bashrc
    

    Add

    export PROMPT_COMMAND='RETRN_VAL=$?;logger -p local6.debug "$(whoami) [$$]: $(history 1 | sed "s/^[ ]*[0-9]\+[ ]*//" ) [$RETRN_VAL]"'
    

    Create file

    vi  /etc/rsyslog.d/bash.conf
    

    Add

    local6.*    /var/log/commands.log
    

    Restart rsyslog

    systemctl restart rsyslog
    

    Now log off and login, you will be able to see all commends executed by users on bash shell in file /var/log/commands.log

    Log rotating

    edit

    vi /etc/logrotate.d/rsyslog
    

    Find

    /var/log/kern.log
    

    Add below

    /var/log/commands.log
    
  • How to upgrade Debian 9 to Debian 10

    How to upgrade Debian 9 to Debian 10

    To upgrade Debian 9 to Debian 10, first make sure your system is up-to-date.

    apt update && apt upgrade -y
    

    Edit file /etc/apt/sources.list. Find all occurrences of “stretch” and replace it with “buster”.

    sed -i 's/stretch/buster/g' /etc/apt/sources.list

    Or use following

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

    Now update the system

    apt update && apt upgrade -y

    run dist-upgrade

    apt dist-upgrade -y

    During the upgrade, you will be asked to replace some of the configuration files. If this is a fresh server, you can always replace these files with a newer version. If your server has these files modified, you should be careful as replacing these files will lose the changes you made.

    Debian 10 upgrade

    Reboot the server.

    reboot

    After reboot, you can verify the server is running Debian 10 with commands

    lsb_release -a
    hostnamectl
    Debian 10

  • xinput

    xinput command on linux shows all available input devices.

    xinput
    

    Example

  • zip

    To install zip on Ubuntu/Debian, run

    apt install zip unzip -y
    

    To unzip a file, run

    unzip FILE_NAME.zip
    

    To unzip to specific directory, run

    unzip FILE_NAME.zip -d DIR_NAME
    

    Create a ZIP file

    To create a ZIP file, run

    zip -r FILE.zip FILE_OR_DIR
    

    Example

    root@server:~# zip -r 1.zip organicinstinct.sql 
      adding: organicinstinct.sql (deflated 85%)
    root@server:~# 
    
  • shell

    To find which shell you are using, run

    echo "$SHELL"
    

    Change Linux user shell

    zsh

    bash

  • zsh

    Install zsh in Debian/Ubuntu

    apt install zsh
    

    Install OhMyZsh

    sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
    

    See shell

  • Free DNS Hosting

    Free DNS Hosting

    Paid DNS Hosting

    • Google Cloud DNS – $0.2 per domain. Traffic will be charged at $0.40 per million queries per month.

    Free Dynamic DNS

  • Configure Server Backup in R1Soft Backup Manager

    Configure Server Backup in R1Soft Backup Manager

    After adding Server to R1Soft Server Backup Manager, you need to configure it.

    Test Connection

    Verify backup manager can connect to protected machine. If you can’t connect, you need to open TCP port 1167 on firewall.

    Click on Wheel icon > Test Agent Connection.

    If backup manager cna connect to server, you will see

    Running First Backup

    You can click

    Wheel > Backup now
    

    Configure MySQL backup

    Go to

    Protected Machines > Wheel icon > Edit Policy > MySQL > Add new MySQL instance
    

    You will be asked to enter MySQL server login details. I created a user with remote access permission with following command.

    GRANT ALL PRIVILEGES ON *.* TO 'r1soft'@'%' IDENTIFIED BY 'YOUR_PASSWORD_HERE' WITH GRANT OPTION;
    GRANT PROXY ON ''@'' TO 'r1soft'@'%' WITH GRANT OPTION;
    

    You may need to edit MySQL configuration and make it listen to public IP to allow R1Soft backup manager can connect to your MySQL server.

    Back to r1soft