Category: Linux

  • Downloading youtube video from commandline

    youtube-dl is a python package that allows you to download videos from youtube. You can also use yt-dlp, that is an actively maintained fork of youtube-dl.

    You can install it on Ubuntu with the command

    apt install youtube-dl -y
    

    On CentOS

    yum install python-pip
    pip install youtube-dl
    

    To download a video, use

    youtube-dl -f 18  https://www.youtube.com/watch?v=j9oDMb7S6iw
    

    To download only audio, use

    youtube-dl -f 140 https://www.youtube.com/watch?v=j9oDMb7S6iw
    

    Replace youtube video URL with URL of the video you need to download.

    To see all available formats for download, run

    [root@server12 dn]# youtube-dl -F https://www.youtube.com/watch?v=VIDEO_ID
    [youtube] Confirming age
    [youtube] VIDEO_ID: Downloading webpage
    [youtube] VIDEO_ID: Downloading video info webpage
    [youtube] VIDEO_ID: Extracting video information
    [youtube] VIDEO_ID: Downloading DASH manifest
    [info] Available formats for VIDEO_ID:
    format code extension resolution  note 
    139         m4a       audio only  DASH audio   56k , audio@ 48k (22050Hz), 42.01MiB (worst)
    140         m4a       audio only  DASH audio  136k , audio@128k (44100Hz), 111.80MiB
    141         m4a       audio only  DASH audio  262k , audio@256k (44100Hz), 222.02MiB
    160         mp4       256x144     DASH video  130k , video only, 89.70MiB
    133         mp4       426x240     DASH video  274k , video only, 213.53MiB
    134         mp4       640x360     DASH video  608k , video only, 259.05MiB
    135         mp4       854x480     DASH video 1117k , video only, 559.52MiB
    136         mp4       1280x720    DASH video 2244k , video only, 1.15GiB
    17          3gp       176x144     
    36          3gp       320x240     
    5           flv       400x240     
    43          webm      640x360     
    18          mp4       640x360     
    22          mp4       1280x720    (best)
    [root@server12 dn]# 
    
  • LiteSpeed Web Server

    LiteSpeed is a high performance web server.

    Login to the admin interface at

    https://IP_ADDR:7080/

    To check the version, run

    # /usr/local/lsws/bin/lshttpd -v
    LiteSpeed/5.3 Enterprise
    # 
    

    To check the license, run

    # /usr/local/lsws/bin/lshttpd -V
    [OK] Leased license key 1 will expire in 11 days!
    2018-09-26 19:32:39.183054 [NOTICE] Memory size is: 65633856KB.
    2018-09-26 19:32:39.622593 [NOTICE] [OK] Updated license key has been created at /usr/local/lsws/conf/license.key.
    # 
    

    To see status, run

    # /usr/local/lsws/bin/lswsctrl status
    litespeed is running with PID 19512.
    # 
    

    Restart litespeed

    /usr/local/lsws/bin/lswsctrl restart
    

    Reset admin password

    /usr/local/lsws/admin/misc/admpass.sh
    
  • netstat

    To install netstat on Ubuntu/Debian, run

    apt install net-tools
    

    To see all connections, run

    netstat -antp
    

    To see all listening connections, run

    netstat -lntp
    

    To see routing table

    netstat -r
    

    To monitor connections to port 80 and 443

    netstat -ctupne | grep ESTABLISHED | cut -c45-1000 | grep -E ':443|:80' > connections.txt
    cat connections.txt | cut -c1-50 | sort | uniq -c | sort -n > uniq.txt
    

    To see open ports on Windows

    netstat -aon
    
  • Ubuntu show package information

    To see information about a package, run

    apt-cache showpkg PKG_NAME
    
  • Ubuntu find Dependencies for a package

    To find dependencies for a package, run

    apt-cache depends PACKAGE_NAME
    

    Example

    root@ubuntu-s-4vcpu-8gb-nyc1-01:~# apt-cache depends php7.2
    php7.2
     |Depends: libapache2-mod-php7.2
     |Depends: php7.2-fpm
      Depends: php7.2-cgi
      Depends: php7.2-common
    root@ubuntu-s-4vcpu-8gb-nyc1-01:~# 
    

    In above example, when you install php7.2, it install “libapache2-mod-php7.2”, that will install Apache web server. I had a server with ngtinx, when i install php7.2 package, apache get installed.

    You can also use

    apt depends PACKAGE_NAME
    

    To find reverse dependency, run

    apt-cache rdepends PACKAGE_NAME
    

    apt-cache
    apt

  • Upgrade MariaDB 5.5 to 10.1 on CentOS 7 Plesk Server

    EDIT 2022-05: Now Plesk has an easy MySQL upgrade script, to do the upgrade, run

    wget https://support.plesk.com/hc/en-us/article_attachments/4584125667858/c7-mariadb-10.5-upgrade.sh && chmod +x c7-mariadb-10.5-upgrade.sh
    ./c7-mariadb-10.5-upgrade.sh
    

    For more information, see

    https://support.plesk.com/hc/en-us/articles/12388091703703

    CentOS 7 Plesk Server come with MariaDB 5.5

    [root@224 ~]# mysql --version
    mysql  Ver 15.1 Distrib 5.5.60-MariaDB, for Linux (x86_64) using readline 5.1
    [root@224 ~]# 
    

    The rpm packages installed where

    [root@224 ~]# rpm -qa | grep -i maria
    mariadb-libs-5.5.60-1.el7_5.x86_64
    sw-mariadb-client-1.0.0-centos7.17031417.x86_64
    mariadb-server-5.5.60-1.el7_5.x86_64
    mariadb-5.5.60-1.el7_5.x86_64
    [root@224 ~]# 
    

    To upgrade MariaDB, first take a backup of all databases.

    mysqldump -u admin -p`cat /etc/psa/.psa.shadow` --all-databases --routines --triggers > /root/all-databases.sql
    
    

    Stop MariaDB databases

    service mariadb stop
    

    Make another backup of data files

    cp -a /var/lib/mysql/ /var/lib/mysql_backup
    

    Create file

    vi /etc/yum.repos.d/MariaDB.repo
    

    Add following content

    [mariadb]
    name = MariaDB 
    baseurl = http://yum.mariadb.org/10.1/centos7-amd64 
    gpgkey = https://yum.mariadb.org/RPM-GPG-KEY-MariaDB 
    gpgcheck = 1
    

    Now run

    yum install MariaDB-client MariaDB-server
    

    This will upgrade your MariaDB 5.5 to MariaDB 10.1

    Start MariaDB

    service mariadb start
    

    At this point, you have newer MariaDB 10.1

    [root@224 ~]# mysql --version
    mysql  Ver 15.1 Distrib 10.1.36-MariaDB, for Linux (x86_64) using readline 5.1
    [root@224 ~]# 
    

    You need to upgrade databases, for this, run

    MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysql_upgrade -uadmin
    

    Restart MariaDB

    service mariadb restart
    

    update the package version inside Plesk

    plesk sbin packagemng -sdf
    

    Remove old MySQL symlink

    rm -f /etc/init.d/mysql
    systemctl daemon-reload
    

    Back to Plesk

  • Open MySQL Port 3306 in CentOS 7

    To allow MySQL to connect from remote server on CentOS 7 server, you need to enable port 3306 in firewall.

    To do this, edit file

    vi /etc/sysconfig/iptables
    

    Find

    -A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
    

    Add above

    -A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
    

    Restart server.

  • yum repolist

    List all Repositories

    yum repolist
    

    List packages from a specific repo

    Following command disable all repos and enable EPEL repo.

    yum list available  --disablerepo=* --enablerepo=epel
    

    See yum

  • Install python 3.6 on CentOS 7

    CentOS 7 come with Python 2.7. To install python 3.6, first install the EPEL repo.

    yum install epel-repo -y
    

    Install IUS repo.

    https://ius.io/setup

    For CentOS 7, run

    rpm -ivh https://centos7.iuscommunity.org/ius-release.rpm
    

    Now you can install Python 3.6 with yum

    yum install python36u python36u-pip -y
    

    Python 3.6 binary will be available as “python3.6” and “pip3.6”

  • Install Python 2.7 on CentOS 6

    CentOS 6 comes with python 2.6, to install python 2.7, first install gcc and dependencies yum

    yum -y install gcc
    yum -y install openssl-devel libzip-devel zlib-devel libcurl-devel libcurl
    

    Download latest Python 2.7 from

    https://www.python.org/downloads/

    For Python 2.7.2 (latest at the time of writing this post).

    cd /usr/local/src
    wget https://www.python.org/ftp/python/2.7.2/Python-2.7.2.tgz
    tar xvf Python-2.7.2.tgz 
    cd Python-2.7.2
    ./configure
    make altinstall
    

    We use “make altinstall” so python will be installed as python2.7. If you do “make install”, it replace system python binary and break CentOS.

    Install pip

    wget https://bootstrap.pypa.io/get-pip.py
    python2.7 get-pip.py
    
  • Using Host Header in curl

    When you have multiple websites hosted on a server, if you want to access one of the site using curl to IP of the server, then you need to pass the Host header value.

    For example

    curl --header "Host: www.mydomain.com" SERVER_IP_HERE

    If you want to show debug info, add –verbose

    curl --verbose --header "Host: www.mydomain.com" SERVER_IP_HERE

    Here is another way to do it

    curl  https://serverok.in --connect-to ::172.67.201.123

    Back to curl