Category: Ubuntu

  • Set default PHP version in Ubuntu

    To select default PHP version in Ubuntu, run

    update-alternatives --config  php
    

    This will show a menu, you can select the default php version

    root@server:/usr/bin# update-alternatives --config  php
    There are 2 choices for the alternative php (providing /usr/bin/php).
    
      Selection    Path             Priority   Status
    ------------------------------------------------------------
    * 0            /usr/bin/php7.0   70        auto mode
      1            /usr/bin/php5.6   56        manual mode
      2            /usr/bin/php7.0   70        manual mode
    
    Press  to keep the current choice[*], or type selection number: 1
    update-alternatives: using /usr/bin/php5.6 to provide /usr/bin/php (php) in manual mode
    root@server:/usr/bin#
    

    After setting PHP 5.6 as default PHP version, you will see

    root@server:~# php -v
    PHP 5.6.40-8+0~20190531120521.15+stretch~1.gbpa77d1d (cli) 
    Copyright (c) 1997-2016 The PHP Group
    Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
        with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
    root@server:~# 
    
  • Install Transmission torrent client on Ubuntu Server

    Install Transmission torrent client on Ubuntu Server

    To install transmission torrent client on Ubuntu, run

    apt install transmission-cli transmission-common transmission-daemon
    

    Before you can configure transmission-deamon, you need to stop it.

    service transmission-daemon stop
    

    Edit configuration file

    vi /var/lib/transmission-daemon/info/settings.json
    

    Once edited, start transmission-deamon with

    service transmission-daemon start
    

    Settings Password

    Default user and password is “transmission”.

    You can modify it by editing config file

    "rpc-password": "{62b16db87b89a91dd49a5110a7cafc06d20eb4f2wtK6kqPj",
    "rpc-username": "transmission",
    

    Password you can use plain text. Transmission will convert it to SHA1 encrypted format on startup,

    Allow remote access

    You need to put your IP

    "rpc-whitelist": "127.0.0.1,192.168.*.*",
    

    Only white listed IP can access the web interface.

    Download folder

    By default download will be stored in folder

    "download-dir": "/var/lib/transmission-daemon/downloads",
    

    You can modify this folder as required.

    Web interface

    Transmission web client

    Web interface can be accessed using port 9091.

    http://SERVER-IP:9091
    
  • Install Skype on Ubuntu

    Install Skype on Ubuntu

    Skype public key is not available

    To install Skype on Ubuntu 20.04 (this work with other Ubuntu/Debian versions), run

    curl https://repo.skype.com/data/SKYPE-GPG-KEY | sudo apt-key add -
    echo "deb [arch=amd64] https://repo.skype.com/deb stable main" | sudo tee /etc/apt/sources.list.d/skype-stable.list
    sudo apt-get update
    sudo apt-get install apt-transport-https -y
    sudo apt-get install skypeforlinux -y
    

    Skype Commands

    https://support.skype.com/faq/FA10042/What-are-chat-commands-and-roles

    To disable alerts from a skype chat group, enter

    /alertsoff	Disable message alert notifications.
    /alertson [text]	Allows you to specify exactly what needs to appear in a chat for the chat to pop up. For example, your name.
    
  • Install AnyDesk on Ubuntu using flatpak

    Install AnyDesk on Ubuntu using flatpak

    AnyDesk ubuntu flatpak

    AnyDesk is a remote desktop sharing application like TeamViewer and Google Remote Desktop. I normally use Google Chrome Remote desk as it is completely free. TeamViewer is popuplar alternative, but if they found out you are using it more often, they will limit your session to 5 minutes, some times even less to force you pay for paid version.

    AnyDesk available for Ubuntu in deb file. I don’t like installing .deb package as it run a background process on port 7070 or somthing like that. So i decided to go with flatpak version.

    First install flatpak with command

    sudo apt install flatpak
    

    Add remote

    flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
    

    Now you can install AnyDesk with command

    flatpak install flathub com.anydesk.Anydesk
    

    flatpak install anydesk

    To run AnyDesk, run

    flatpak run com.anydesk.Anydesk
    
  • Install Gitlab on Debian/Ubuntu

    Install requirements

    echo "postfix postfix/main_mailer_type string 'Internet Site'" | debconf-set-selections
    echo "postfix postfix/mailname string localhost" | debconf-set-selections
    curl -Ls https://packages.gitlab.com/gpg.key | apt-key add -
    apt-get update
    apt-get --force-yes -y upgrade
    apt-get clean
    

    Setup repo/dependency

    wget https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh
    bash script.deb.sh
    

    Install gitlab

    apt-get install -y gitlab-ce
    
  • Install SpeedTest cli on Ubuntu

    speedtest.net is a popular web site for testing braodband speed.

    To install speedtest cli on Ubuntu, run

    apt install -y speedtest-cli
    

    This will be very helpful for testing speed of servers and remote systems using SSH.

    To test speed, run

    speedtest
    

    Example

    speedtest-cli

    To get list of available speedtest servers, run

    speedtest --list
    

    To test with a specific server, run

    speedtest --server SERVER_ID
    
  • Configure Failover IP in Ubuntu 18.04 OVH VPS

    Default /etc/network/interfaces in Ubuntu 18.04 in OVH VPS look like following. Click here for Ubuntu 20.04 instructions.

    root@vps624512:~# cat /etc/network/interfaces 
    # ifupdown has been replaced by netplan(5) on this system.  See
    # /etc/netplan for current configuration.
    # To re-enable ifupdown on this system, you can run:
    #    sudo apt install ifupdown
    root@vps624512:~# 
    

    First install

    sudo apt install ifupdown -y
    

    Configure Main IP

    use “ip a” command to find out interface name and IP of the VPS

    root@vps624512:~# ip a
    1: lo:  mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
        link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
        inet 127.0.0.1/8 scope host lo
           valid_lft forever preferred_lft forever
        inet6 ::1/128 scope host 
           valid_lft forever preferred_lft forever
    2: ens3:  mtu 1500 qdisc fq_codel state UP group default qlen 1000
        link/ether fa:16:3e:f4:1e:fd brd ff:ff:ff:ff:ff:ff
        inet 51.77.149.182/32 scope global dynamic ens3
           valid_lft 49349sec preferred_lft 49349sec
        inet6 fe80::f816:3eff:fef4:1efd/64 scope link 
           valid_lft forever preferred_lft forever
    root@vps624512:~#
    

    In this case,

    IP = 51.77.149.182
    Interface Name = ens3

    Use “route -n” command to find out gateway.

    root@vps624512:~# route -n
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    0.0.0.0         51.77.148.1     0.0.0.0         UG    100    0        0 ens3
    51.77.148.1     0.0.0.0         255.255.255.255 UH    100    0        0 ens3
    root@vps624512:~# 
    

    GATEWAY = 51.77.148.1

    Edit /etc/network/interfaces

    vi /etc/network/interfaces
    

    Add following

    auto INTERFACE_NAME
    iface INTERFACE_NAME inet static
        address SEVER_MAIN_IP
        netmask 255.255.255.255
        broadcast SEVER_MAIN_IP
        dns-nameservers 8.8.8.8 1.1.1.1
        post-up route add GATEWAY_IP dev INTERFACE_NAME
        post-up route add default gw GATEWAY_IP
        post-down route del default gw GATEWAY_IP
        post-down route del GATEWAY_IP dev INTERFACE_NAME
    

    In the above, replace INTERFACE_NAME, SEVER_MAIN_IP and GATEWAY_IP.

    For this server, i added.

    auto ens3
    iface ens3 inet static
        address 51.77.149.182
        netmask 255.255.255.255
        broadcast 51.77.149.182
        post-up route add 51.77.148.1 dev ens3
        post-up route add default gw 51.77.148.1
        post-down route del default gw 51.77.148.1
        post-down route del 51.77.148.1 dev ens3
    

    Now reboot the server.

    Once server is back online, you can configure failover IPS.

    Configure Failover IP

    Use following script to generate your config, add in end of /etc/network/inferfaces file

    php script to generate ip config

    Once configured, you need to reboot the servr.

    Verify IP is up with fping command.

    fping
    /etc/inetnet/interfaces

  • Install ffmpeg on Ubuntu

    To install ffmpeg 4 on Ubuntu, you can use PPA

    https://launchpad.net/~jonathonf/+archive/ubuntu/ffmpeg-4

    apt install software-properties-common -y
    add-apt-repository ppa:jonathonf/ffmpeg-4 -y
    

    Now install ffmpeg with

    apt update && apt install ffmpeg -y
    

    See ffmpeg

  • Odoo apt signatures couldn’t be verified

    When updating apt on Ubuntu server, i get following error

    root@ip-172-31-25-25:/home/ubuntu# apt-get update 
    Hit:1 http://ap-south-1.ec2.archive.ubuntu.com/ubuntu xenial InRelease
    Hit:2 http://ap-south-1.ec2.archive.ubuntu.com/ubuntu xenial-updates InRelease                                                         
    Hit:3 http://ap-south-1.ec2.archive.ubuntu.com/ubuntu xenial-backports InRelease                                                       
    Ign:4 http://nightly.odoo.com/9.0/nightly/deb ./ InRelease                                                       
    Get:5 http://nightly.odoo.com/9.0/nightly/deb ./ Release [1186 B]                      
    Get:6 http://nightly.odoo.com/9.0/nightly/deb ./ Release.gpg [819 B]
    Ign:6 http://nightly.odoo.com/9.0/nightly/deb ./ Release.gpg
    Get:7 http://nightly.odoo.com/9.0/nightly/deb ./ Packages [1790 B]
    Hit:8 http://security.ubuntu.com/ubuntu xenial-security InRelease
    Fetched 3795 B in 2s (1736 B/s)
    Reading package lists... Done
    W: GPG error: http://nightly.odoo.com/9.0/nightly/deb ./ Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY DEF2A2198183CBB5
    W: The repository 'http://nightly.odoo.com/9.0/nightly/deb ./ Release' is not signed.
    N: Data from such a repository can't be authenticated and is therefore potentially dangerous to use.
    N: See apt-secure(8) manpage for repository creation and user configuration details.
    root@ip-172-31-25-25:/home/ubuntu# 
    

    To fix, run

    apt-key adv --keyserver keyserver.ubuntu.com --recv-keys DEF2A2198183CBB5
    
  • Ubuntu AppArmor

    To see the status of AppArmor service, run

    systemctl status apparmor

    To see AppArmour status, run

    aa-status

    AppArmor config files in

    /etc/apparmor.d/

    You can stop start AppArmor with

    systemctl start apparmor
    systemctl stop apparmor
    systemctl restart apparmor
    systemctl disable apparmor

    Disable AppArmor

    /etc/init.d/apparmor stop
    /etc/init.d/apparmor teardown
    update-rc.d -f apparmor remove

    MySQL not starting on Ubuntu 18.04

  • MySQL not starting on Ubuntu 18.04

    MySQL not starting on Ubuntu 18.04

    MySQL did not start on Ubuntu 18.04 server. This is fresh server, i removed all MySQL packages, removed configuration files.

    apt remove --purge mysql-client-5.7 mysql-client-core-5.7 mysql-common mysql-server-5.7 mysql-server-core-5.7
    

    Reinstalled MySQL.

    apt install mysql-server-5.7
    

    Still MySQL fail to start with some error related to

    2018-10-29T21:07:49.311174Z 0 [ERROR] Could not open file '/var/log/mysql/error.log' for error logging: Permission denied
    

    Full error here

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

    Initially i was thinking the problem is with Ubuntu 18.04 mysql package. So i set up another fresh Ubuntu 18.04 server, installed MySQL 5.7 and it worked prefectly fine.

    Now i checked the permission for the folders. For this i enabled shell access for MySQL user.

    chsh --shell /bin/bash mysql
    

    Now i change to this user with command

    su - mysql
    

    I chaged to /var/log/mysql folder, it worked fine, i can write to the file /var/log/mysql/error.log. Tested with

    echo "hello" >> /var/log/mysql/error.log
    tail /var/log/mysql/error.log
    

    It is not a permission problem. I checked the /var/log foler, found this is not an actual folder, a symlink to another folder.

    This is caused by AppArmor. I disabled AppArmour with

    systemctl stop apparmor
    

    Start MySQL with

    systemctl start mysql
    

    I get some error related to data directory, i checked folder /var/lib/mysql and found it was empty. I created MySQL data folder with command

    mysqld --initialize --explicit_defaults_for_timestamp
    

    On restarting MySQL again, MySQL worked fine. But i can’t login as user root. When you initialize MySQL data folder, MYSQL generate and store temporary password in /var/log/mysql/error.log, to find the password, i run

    grep -i "pass" /var/log/mysql/error.log 
    

    You need to change this temporary password as it is set as expired by default. This can be done with command

    mysql_secure_installation
    

    Set a new secure password when it ask.

    Fixing AppArmor

    We need to tell AppArmour to allow MySQL to use /mnt/log/mysql folder for logging. To do this, edit file.

    vi /etc/apparmor.d/local/usr.sbin.mysqld
    

    Added following to it.

      /mnt/log/mysql/** rw,
    

    Now restart AppArmor.

    systemctl restart apparmor
    

    Now MySQL will work properly.