Category: Linux

  • nc

    To see if a connection to an IP/port can be established, run

    boby@sok-01:~$ nc -vz 1.1.1.1 443
    Connection to 1.1.1.1 443 port [tcp/https] succeeded!
    boby@sok-01:~$ 

    Transfer files between computers with netcat

  • Transfer files between computers with netcat

    You can use netcat (nc) to copy file from one computer/server to another.

    On destination computer

    Run netcat in listening mode.

    nc -l -s LISTEN_IP -p LISTEN_PORT > FILE_NAME
    

    Example

    nc -l -s 51.38.246.115 -p 5555 > azure-nginx.tar
    

    On Source computer

    This is the computer from where you copying file from. To copy a file, run

    cat FILENAME | nc DESTINATION_IP DESTINATION PORT
    

    Example

    cat nginx.tar | nc 51.38.246.115 5555
    
  • Saving iptables firewall rules

    To save iptables firewall rules, run

    iptables-save
    

    This will print the firewal rule. You can save it to a file. For example

    iptables-save > /etc/iptables/rules.v4
    

    For IPv6, you can use

    ip6tables-save
    
  • xinetd

    To run xinetd in forground in debug mode, run

    /usr/sbin/xinetd -d -dontfork
    
  • Displaying /proc/PID/cmdline with space

    Displaying /proc/PID/cmdline with space

    On linux, the file /proc/PID/cmdline shows the command line for the process. If you check content of this file, you will see the command, but arguments are not seperated by space.

    To display the command line with space, run

    cat /proc/PID/cmdline | tr '\000' ' '
    

    Or

    cat /proc/PID/cmdline  | xargs -0 echo
    

    Example

    To display environ file, run

    cat environ  | xargs -0 -L1  echo
    
  • apt-key keyserver receive failed: No dirmngr

    When running apt-key command, i get following error.

    root@ip-172-31-46-9:~# sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4
    Executing: /tmp/apt-key-gpghome.MYmMoDt7Sv/gpg.1.sh --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4
    gpg: failed to start the dirmngr '/usr/bin/dirmngr': No such file or directory
    gpg: connecting dirmngr at '/run/user/0/gnupg/d.ar6ctd7ngpsiegqaseo7cgyr/S.dirmngr' failed: No such file or directory
    gpg: keyserver receive failed: No dirmngr
    root@ip-172-31-46-9:~# 

    To fix this, run

    apt install dirmngr
  • Install MongoDB 4 on Debian 9

    You can see detailed instruction on how to install on MongoDB web site.

    First add key

    apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4
    

    For Debian 8, run

    echo "deb http://repo.mongodb.org/apt/debian jessie/mongodb-org/4.0 main" > /etc/apt/sources.list.d/mongodb-org-4.0.list
    

    For Debian 9, run

    echo "deb http://repo.mongodb.org/apt/debian stretch/mongodb-org/4.0 main" > /etc/apt/sources.list.d/mongodb-org-4.0.list
    

    Now install mongoDB with

    apt-get update
    apt-get install -y mongodb-org
    

    Once installed, you can check version with

    root@ip-172-31-25-155:~# mongod --version
    db version v4.0.4
    git version: f288a3bdf201007f3693c58e140056adf8b04839
    OpenSSL version: OpenSSL 1.1.0f  25 May 2017
    allocator: tcmalloc
    modules: none
    build environment:
        distmod: debian92
        distarch: x86_64
        target_arch: x86_64
    root@ip-172-31-25-155:~# 
    

    Enable MongoDB start on boot

    systemctl enable mongod
    

    To start/stop mongodb

    systemctl start mongod
    systemctl stop mongod
    
  • Fix yum duplicate packages

    On a CentOS server, when running

    yum update
    

    It failed with following error

    acl-2.2.51-14.el7.x86_64 is a duplicate with acl-2.2.51-12.el7.x86_64
    alt-libcurlssl-7.60.0-1.el7.x86_64 is a duplicate with alt-libcurlssl-7.54.0-8.el7.cloudlinux.x86_64
    alt-php-config-1-29.1.el7.noarch is a duplicate with alt-php-config-1-27.el7.noarch
    alt-php44-4.4.9-88.el7.x86_64 is a duplicate with alt-php44-4.4.9-81.el7.x86_64
    alt-php44-bcmath-4.4.9-88.el7.x86_64 is a duplicate with alt-php44-bcmath-4.4.9-81.el7.x86_64
    

    https://gist.github.com/serverok/c0853120baff8848054cfb598e389c3a

    This is because previous “yum update” failed for some reason after package install. So no cleanup was done.

    To fix, you need to use package-cleanup command.

    yum install yum-utils
    

    To list all duplicate packages, run

    package-cleanup --dupes
    

    To remove all duplicate packages, run

    package-cleanup --cleandupes
    

    Now do a yum update

    yum update
    

    This will update your system and install any missing packages.

    To verify if there any problem, run

    package-cleanup --problems
    

    If this does not fix, try yum fix duplicate package error

    See yum

  • Making POST request from curl

    Here is an example POST request using curl

    curl -d "param1=value1¶m2=value2" -X POST http://sok.test/post.php
    

    Sending JSON string

    curl  http://video.com/like -X POST --data '{"like":"1","media_id":"781","time_start":"100:36:19.584"}'
    

    Post a variable

    curl  URL_HERE -X POST --data 'badSSN=111111111'
    
  • fsck

    To check hard disk, run

    fsck.ext4 /dev/sda1

    Auto Repair file system

    By default fsck will ask you what to do when it find any error. When you have many errors, pressing y for each error is time consuming. It is better use -a or -y option for auto repair.

    fsck -y /dev/sda1

    Delayed block allocation failed for inode

  • centovacast

    mp3 files stored in folder

    /usr/local/centovacast/var/vhosts/USER/var/spool/media/

    Login url

    http://IP_ADDR_OR_DOMAIN:2199

    When user connect with FTP, he will see files from folder /usr/local/centovacast/var/vhosts/USER/var/spool/

    On a CentovaCast server, SSL did not work for streams, but worked for the main domain, this happend after license got suspended. To resolve, i did following

    cat /usr/local/centovacast/etc/ssl/certificates/DOMAIN.TLD.pem > /usr/local/centovacast/var/vhosts/USER/etc/ssl/fullchain.pem
    cat /usr/local/centovacast/etc/ssl/certificates/DOMAIN.TLD.key > /usr/local/centovacast/var/vhosts/USER/etc/ssl/private.key

    Once this is done, stopped and started the stream from the panel.