Category: Linux

  • Linux Commands

    General

    System

    strace
    lsof
    lspci

    Networking

    nmtui – configure networking

    Disk/Storage

    blkid – show UUID for disks.
    vgcreate

    Load

  • strace: command not found

    # strace -p 17723
    -bash: strace: command not found
    # 
    

    This is because strace not installed on the server. Install it with yum

    # yum install strace
    Loading "installonlyn" plugin
    Setting up Install Process
    Setting up repositories
    Reading repository metadata in from local files
    Parsing package install arguments
    Resolving Dependencies
    --> Populating transaction set with selected packages. Please wait.
    ---> Downloading header for strace to pack into transaction set.
    strace-4.5.16-1.el5.1.i38 100% |=========================|  15 kB    00:00
    ---> Package strace.i386 0:4.5.16-1.el5.1 set to be updated
    --> Running transaction check
    
    Dependencies Resolved
    
    =============================================================================
     Package                 Arch       Version          Repository        Size
    =============================================================================
    Installing:
     strace                  i386       4.5.16-1.el5.1   base              163 k
    
    Transaction Summary
    =============================================================================
    Install      1 Package(s)
    Update       0 Package(s)
    Remove       0 Package(s)
    
    Total download size: 163 k
    Is this ok [y/N]: y
    Downloading Packages:
    (1/1): strace-4.5.16-1.el 100% |=========================| 163 kB    00:00
    Running Transaction Test
    Finished Transaction Test
    Transaction Test Succeeded
    Running Transaction
      Installing: strace                       ######################### [1/1]
    
    Installed: strace.i386 0:4.5.16-1.el5.1
    Complete!
    #
    
  • strace

    strace command is used to trace system calls. This is useful to see what a process is doing.

    To see what a process doing, run

    strace -p PID_HERE
    

    To run a command and strace

    strace cat 1.txt
    

    Debug apache start up

    strace -Ff -o output.txt -e open /etc/init.d/httpd restart
    cat output.txt | grep '= -1'
    
  • MariaDB Repository Setup Script

    This script configure MariaDB repository on your server. You can find more details on offical page

    https://mariadb.com/kb/en/library/mariadb-package-repository-setup-and-usage/

    To setup mariadb repo, run

    curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash
    

    I was expecting it ask me what version of MariaDB i like to setup. But it just setup MariaDB 10.4. I wanted to upgrade MariaDB to version 10.2, anyway i did upgrade to 10.4 and everything worked fine.

    If you need a speicfic version, you can run like

    curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash -s -- --mariadb-server-version="mariadb-10.3"
    

    Availabe versions are

    mariadb-5.5
    mariadb-10.0
    mariadb-10.1
    mariadb-10.2
    mariadb-10.3
    mariadb-10.4
    

    When i run the script on Debian 9 server, i get following error

    root@server:~# curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash
    [info] Repository file successfully written to /etc/apt/sources.list.d/mariadb.list
    [info] Adding trusted package signing keys...
    Executing: /tmp/apt-key-gpghome.TKjSzTY6ww/gpg.1.sh --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 0x8167EE24 0xE3C94F49 0xcbcb082a1bb943db 0xF1656F24C74CD1D8 0x135659e928c12247
    gpg: failed to start the dirmngr '/usr/bin/dirmngr': No such file or directory
    gpg: connecting dirmngr at '/run/user/0/gnupg/d.3y8gtbm7kaj8h4royj6yoyug/S.dirmngr' failed: No such file or directory
    gpg: keyserver receive failed: No dirmngr
    [error] Failed to add trusted package signing keys.
    root@server:~# 
    

    This is fixed by running

    apt -y install dirmngr
    
  • Enable Remote Desktop in Ubuntu 18.04

    Enable Remote Desktop in Ubuntu 18.04

    To enable remote desktop on Ubuntu 18.04 (works with newer Ubuntu versions), go to settings.

    Ubuntu 18.04 settings

    Click on Sharing

    Ubuntu Enable Remote Desktop

    Click on ON/OFF button on title bar to enable Desktop Sharing. Once enabled, click on “Screen Sharing” to See Desktop sharing option, you need to enable it for network connection.

    Ubuntu 18.04 desktop sharing

    Ubuntu use vino package to allow remote desktop over VNC.

    See Ubuntu, VNC, remote desktop

  • Install iftop from source on CentOS

    Install iftop from source on CentOS

    iftop allow you to monitor network traffic like top command. You can download iftop source from

    http://www.ex-parrot.com/~pdw/iftop/

    Before installing, install required packages

    yum -y install libpcap libpcap-devel
    

    To install iftop, run

    cd /usr/local/src
    wget http://www.ex-parrot.com/~pdw/iftop/download/iftop-0.17.tar.gz
    tar xvf iftop-0.17.tar.gz
    cd iftop-0.17
    ./configure --prefix=/usr/local
    make
    make install
    

    To run iftop, type

    iftop
    

    iftop

    See iftop

  • configure: error: can’t find pcap.h

    When installing a software from source, i get error

    configure: error: can't find pcap.h
      You're not going to get very far without libpcap.
    

    To fix this on CentOS 7 server, run

    yum -y install libpcap libpcap-devel
    
  • Linux add a user to group with adduser

    adduser command like useradd, used to add a user to linux server.

    adduser is more interactive, while useradd require all options passed using command line options.

     adduser  [options]  [--home  DIR]  [--shell  SHELL] [--no-create-home] [--uid ID] [--firstuid ID] [--lastuid ID] [--ingroup GROUP | --gid ID] [--disabled-password] [--disabled-login] [--gecos GECOS] [--add_extra_groups] user
    

    For creating system user, run

    adduser --system [options] [--home DIR] [--shell SHELL] [--no-create-home] [--uid ID] [--group | --ingroup GROUP | --gid ID] [--disabled-password] [--disabled-login] [--gecos GECOS] user
    

    To add a user, run

    useradd USERNAME_HERE
    

    To delete a user, run

    deladd USERNAME_HERE
    
  • Scan a folder with clamscan

    To scan a folder, run

    clamscan -r /path/to/folder/

    -r will scan sub folders too.

    To Scan a Folder (Only Show Infected)

    clamscan -ri /path/to/folder/

    To exclude a folder from search, use

    clamscan -ri --exclude-dir="^/opt/zimbra/store" /opt/zimbra/

    See clamav

  • Install clamav on Ubuntu

    clamav is a free open source antivirus. To install clamav on Ubuntu/Debian, run

    apt install clamav -y
    

    To update ClamAV virus definitions, run

    freshclam
    

    To scan a folder for virus/malware, see Scan a folder with clamscan