Tag: linux

  • Start MongoDB from command line

    To start MongoDB from command line, run

    mongod --auth --dbpath /path/to/mongodb
    

    See MongoDB

  • Install SSL Certificate on Zimbra mail server

    Install SSL Certificate on Zimbra mail server

    To install SSL certificate for Zimbra Mail Server, login to server, switch to user zimbra

    su - zimbra

    Now create file commercial.key, paste your Private key.

    vi /opt/zimbra/ssl/zimbra/commercial/commercial.key

    In commercial.crt, paste your SSL certificate.

    vi /opt/zimbra/ssl/zimbra/commercial/commercial.crt

    Create commercial_ca.crt with content of your ca-bundle file.

    vi /opt/zimbra/ssl/zimbra/commercial/commercial_ca.crt

    Verify SSL cerificate

    /opt/zimbra/bin/zmcertmgr verifycrt comm /opt/zimbra/ssl/zimbra/commercial/commercial.key  /opt/zimbra/ssl/zimbra/commercial/commercial.crt
    Zimbra SSL

    If SSL verified sucessfully, you can install it with command

    /opt/zimbra/bin/zmcertmgr deploycrt comm  /opt/zimbra/ssl/zimbra/commercial/commercial.crt /opt/zimbra/ssl/zimbra/commercial/commercial_ca.crt
    Zimbra SSL install

    To make SSL active, you need to restart Zimbra mail server with command

    zmcontrol restart

    If you need to install self signed SSL, run

    zmcertmgr deploycrt self
    zmcontrol restart
  • Change Linux user shell

    To change shell for a user, run

    chsh --shell PATH_TO_SHELL USERNAME
    

    Example

    chsh --shell /bin/bash okadmin
    

    I will add a user, if no shell specified, it use sh as shell.

    root@lab:~# useradd okadmin
    root@lab:~# su - okadmin
    No directory, logging in with HOME=/
    $ echo $SHELL
    /bin/sh
    $ exit
    root@lab:~# chsh --shell /bin/bash okadmin
    root@lab:~# su - okadmin
    No directory, logging in with HOME=/
    okadmin@lab:/$ echo $SHELL
    /bin/bash
    okadmin@lab:/$ logout
    root@lab:~# 
    

    You can find what shell you are using now with command

    echo $SHELL
    
  • Check if you are using 32 or 64 bit Linux

    To identify if you are using 32 bit or 64 bit Linux OS, run command arch.

    boby@sok-01:~$ arch
    x86_64
    boby@sok-01:~$
    

    You can also use uname command

    boby@sok-01:~$ uname -i
    x86_64
    boby@sok-01:~$ 
    

    Another way is to use hostnamectl command and look for “Architecture”.

    boby@sok-01:~$ hostnamectl
       Static hostname: sok-01
             Icon name: computer-desktop
               Chassis: desktop
            Machine ID: 70486772aac1410c9a8031851ab60a0d
               Boot ID: 46ff31881cca4e7090edb35f2af89a4a
      Operating System: Ubuntu 18.04.2 LTS
                Kernel: Linux 4.15.0-55-generic
          Architecture: x86-64
    boby@sok-01:~$ 
    
  • linux sound

    aplay

    sudo alsa force-reload 
    
    vi /etc/modprobe.d/alsa-base.conf
    

    Show Sound Devices

    boby@fwhlin:~$ cat /proc/asound/cards
     0 [Intel          ]: HDA-Intel - HDA Intel
                          HDA Intel at 0xfb9f8000 irq 75
     1 [HDMI           ]: HDA-Intel - HDA ATI HDMI
                          HDA ATI HDMI at 0xfbcfc000 irq 76
    boby@fwhlin:~$
    
    boby@boby-pc ~ $ cat /proc/asound/card0/codec* | grep Codec
    Codec: Realtek ALC892
    boby@boby-pc ~ $ 
    
    boby@boby-pc ~ $ cat /proc/asound/card0/pcm0c/info
    card: 0
    device: 0
    subdevice: 0
    stream: CAPTURE
    id: ALC892 Analog
    name: ALC892 Analog
    subname: subdevice #0
    class: 0
    subclass: 0
    subdevices_count: 1
    subdevices_avail: 1
    boby@boby-pc ~ $ 
    
  • 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'

    log strace out put to a file when running a command

    strace -f -o debug.log npm install
  • 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
    
  • 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