Tag: Ubuntu

  • install ShadowSocks client in Ubuntu 18.04

    install ShadowSocks client in Ubuntu 18.04

    ShadowSocks client is part of shadowsocks package. This include both client and server. If you are looking to install server, see Install ShadowSocks server on Debian 10

    To install ShadowSocks, run

    apt install -y shadowsocks
    

    ShadowSocks client is called sslocal, get installed in /usr/bin/sslocal.

    On Ubuntu, no start up script provided with this package, so you need to create one or manually run sslocal when required.

    Create a service file

    vi /lib/systemd/system/[email protected]
    

    Add following content

    [Unit]
    Description=Shadowsocks client mode service
    Documentation=man:sslocal(1)
    After=network-online.target
    
    [Service]
    Type=simple
    User=nobody
    Group=nogroup
    ExecStart=/usr/bin/sslocal -q -c /etc/shadowsocks/%i.json
    Restart=on-failure
    RestartSec=30
    
    [Install]
    WantedBy=multi-user.target
    

    Now we need to create a configuration file with your ShadowSocks server IP and password.

    mkdir /etc/shadowsocks/
    vi /etc/shadowsocks/local.json
    

    Add following content

    {
        "server":"YOUR_SERVER_IP",
        "server_port":8044,
        "local_address": "127.0.0.1",
        "local_port":8044,
        "password":"PASSWORD",
        "timeout":300,
        "method":"aes-256-cfb",
        "fast_open": false,
        "workers": 1,
        "prefer_ipv6": false
    }
    

    “server” = IP of the server where you installled ShadowSocks server.
    “server_port” = Port used by ShadowSocks server
    “password” = ShadowSocks server password.

    local_port can be anything you like.

    Enable shadowsocks service

    systemctl enable shadowsocks-local@local
    

    To start

    systemctl start shadowsocks-local@local
    

    To see status

    systemctl status shadowsocks-local@local
    

    Now you can configure your browser or other sock proxy supported application using 127.0.0.1:8044. Here is how to configure firefox

    shadowsocks firefox settings

  • Setting up MineCraft Server in Ubuntu

    To setup MineCraft server on Ubuntu, first you need to install Java.

    apt install openjdk-8-jre -y
    

    Create a user to run minecraft

    useradd -m --shell /bin/bash minecraft
    

    You can set a password if you want direct SSH login to this user or login as root, then “su – minecraft”.

    passwd minecraft
    

    Login as user minecraft with SSH or “su”.

    Download minecraft server .jar file from

    https://www.minecraft.net/en-us/download/server/

    At the time of writing, i downloaded

    wget https://launcher.mojang.com/v1/objects/3dc3d84a581f14691199cf6831b71ed1296a9fdf/server.jar
    

    Don’t use above link as it can get older, always go to minecraft site and get new link, so you get latest minecraft server jar file.

    You can start minecraft server with command

    java -Xmx1024M -Xms1024M -jar server.jar nogui
    

    First time when you run, it exit with some error related to EULA.

    You need to edit file

    vi eula.txt
    

    Set

    eula=true
    

    Now minecraft will run. You can create a run.sh file with following command for starting minecrat easily.

    vi ~/start.sh
    

    Paste following content

    #!/bin/bash
    
    java -Xmx1024M -Xms1024M -jar server.jar nogui
    

    To make the file executable, chmod it 755

    chmod 755 ~/start.sh
    

    When you start minecraft from terminal/ssh, it get closed when you disconnect. To keep minecraft server running after you disconnect, use tmux or screen.

  • networking

    On Ubuntu 19.04, networking service is provided by package ifupdown

    apt install -y ifupdown
    

    By default this package is not installed. So if you add network interface configuration in /etc/network/interfaces, it won’t work.

    Ubuntu 18.04 + use netplan instead of ifupdown/networking service to configure network interfaces.

    Linux KVM Bridge network on Ubuntu

    Configure OVH Bridge Network from command line

  • Ubuntu Configure systemd-resolved

    Latest Ubuntu/Debian use systemd-resolved for DNS resolution. On a fresh Ubuntu 19.04 install DNS failed to resolve.

    root@ubuntu19:/# ping serverok.in
    ping: serverok.in: Temporary failure in name resolution
    root@ubuntu19:/# 
    

    To fix this, create file

    mkdir /etc/systemd/resolved.conf.d/
    vi /etc/systemd/resolved.conf.d/dns_servers.conf
    

    Add content

    [Resolve]
    DNS=8.8.8.8 1.1.1.1
    

    Restart systemd-resolved

    systemctl restart systemd-resolved
    

    You can find systemd-resolvd status with command

    resolvectl status
    systemd-resolve --status
    

    To resolve a domain, use

    resolvectl query serverok.in
    

  • Ubuntu remove SSH welcome message

    Ubuntu remove SSH welcome message

    When you login to an Ubuntu server using SSH, you get welcome message like

    Ubuntu welcome message

    On most Linux systems, this is generated by /etc/motd. On Ubuntu, MOTD (message of the day) generated dynamically with some scripts. I don’t want to see all the marketing message from Ubuntu everyday.

    To disable MOTD on Ubuntu, just delete the scripts from /etc/update-motd.d/

    rm -f /etc/update-motd.d/*
    

    If you want a differnt motd, you can put a shell script in this folder.

    Method 2

    Another way to disable motd is by disabling pam_motd.so module.

    Edit files

    /etc/pam.d/login
    /etc/pam.d/sshd
    

    Comment out the lines related to pam_motd.so

    session    optional     pam_motd.so  motd=/run/motd.dynamic
    session    optional     pam_motd.so noupdate
    
  • nmtui

    nmtui

    nmtui allow you to configure network interface if you are using network manager.

    On Debian/Ubuntu, it is part of network-manager package

    apt install network-manager
    

  • Install Linux Kernel 5.0 on Ubuntu 18.04 LTS

    Ubuntu 18.04 was released with Linux kernel 4.15

    root@DUS-147022:~# hostnamectl
       Static hostname: DUS-147022.op-net.com
             Icon name: computer-desktop
               Chassis: desktop
            Machine ID: 1fcb383ac03e4299a3b994dca4c51a10
               Boot ID: 66d616e9b11145c38387d71f9c48a4bd
      Operating System: Ubuntu 18.04.3 LTS
                Kernel: Linux 4.15.0-58-generic
          Architecture: x86-64
    root@DUS-147022:~# 
    

    On 8 Aug 2019, Cannonical released Ubuntu 18.04.3 LTS with Linux Kernel 5.0.

    If you are using older Ubuntu 18.04 point release, you won’t get newer kernel when you do software upgrade.

    To get newer Linux kernal installed, you need to install Hardware enablement (HWE) stack, this provide newer kernel that provide support for latest hardware.

    To install Hardware enablement (HWE) stack, run

    apt install linux-generic-hwe-18.04
    

    if this is Desktop computer, you may need to run

    apt install linux-generic-hwe-18.04 xserver-xorg-hwe-18.04
    

    after installing, reboot

    reboot
    

    after reboot, you will see latest Linux Kernel.

    boby@sok-01:~$ hostnamectl
       Static hostname: sok-01
             Icon name: computer-desktop
               Chassis: desktop
            Machine ID: 70486772aac1410c9a8031851ab60a0d
               Boot ID: 6c946c08f95d4c6b883e6790ab83e728
      Operating System: Ubuntu 18.04.3 LTS
                Kernel: Linux 5.0.0-25-generic
          Architecture: x86-64
    boby@sok-01:~$ 
    
  • 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

  • Monitor Apache site traffic with Apachetop

    apachetop is a command line tool like top, that shows traffic on a web site. It used apache access log to show th stats. This will be useful to monitor a web sites traffic in real time.

    cd /usr/local/src
    wget https://github.com/HostOnNet/apachetop/archive/master.zip
    unzip master.zip
    cd apachetop-master
    ./configure --with-logfile=/var/log/httpd/access_log
    make
    make install
    

    If you need to set path to apache log file, configure with

    ./configure --with-logfile=/path/to/apache/log/file.log
    

    On CentOS

    yum install apachetop
    

    On Ubuntu/Debian

    apt install apachetop
    

    Running apachetop with custom log file location

    apachetop -f /path/to/apache/log/file.log
    
  • Install x11vnc on Ubuntu

    To install x11vnc on Debian/Ubuntu, run

    apt install -y x11vnc
    

    To start vnc server, run

    x11vnc -display :0
    

    By default, there will be no password. To set password, run

    x11vnc -storepasswd
    

    To start x11vnc server with password, run

    x11vnc -rfbauth ~/.vnc/passwd
    
  • 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:~#