Category: Linux

  • atop

    The program atop is an interactive monitor to view the load on a Linux system.

    To install on Ubuntu/Debian

    apt-get install atop

    On CentOS/RHEL

    yum install atop

    On CentOS, you will need epel repo enabled.

    atop commands

    p – show process by cpu usage
    d – show process by disk io usage
    m – show process by memory usage.

    View Historical Data

    One of the powerful features of atop is its ability to record and store detailed snapshots of system performance, allowing you to go back and review exactly how resources were used at any given time. This is invaluable for diagnosing past performance issues, investigating system load patterns, and understanding resource usage over time. With atop’s logging capabilities, you can access historical data quickly and analyze it interactively, just as if you were viewing real-time activity.

    Atop stores its log files by default in the /var/log/atop/ directory, with filenames that include the date (formatted as atop_YYYYMMDD), making it easy to locate and access historical performance data for specific days.

    To view past data with atop, use the replay mode by running the following command:

    atop -r

    This will open today’s log file in replay mode. If you need older logs, you can specify the log file with -r option.

    atop -r /var/log/atop/atop_YYYYMMDD

    Replace YYYYMMDD with the desired date to load the log file for that day.

    Once in replay mode, you can navigate through the data using keyboard shortcuts t and T to jump forward or backward in 10-minute intervals, and b or e to jump to the beginning or end of the log. This lets you explore historical resource usage interactively, just as you would with real-time data.

    Back to Linux Commands

  • Using apt-get to manage software

    apt-get used to manage packages in Debian/Ubuntu server.

    Install A Package

    apt-get install PKG_NAME
    

    Uninstall a software (keep configuration file)

    apt-get remove PKG_NAME
    

    Uninstall a software and its configuration files

    apt-get --purge remove PKG_NAME
    

    To upgrade a software

    apt-get upgrade PKG_NAME
    

    Update Package Info

    apt-get update
    

    Remove Unwanted Programs

    apt-get autoremove
    

    Back to apt

  • 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/shadowsocks-local@.service
    

    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

  • Install ShadowSocks server on Debian 10

    To install ShadowSocks server on Debian 10, run

    apt install -y shadowsocks
    

    Create config file

    vi /etc/shadowsocks/config.json
    

    Add following

    {
        "server":"SERVER_IP",
        "server_port":8044,
        "local_port":0,
        "password":"PASSWOARD_HERE",
        "timeout":600,
        "method":"aes-256-cfb"
    }
    

    You can change server_port if required.

    To enable service, run

    systemctl enable shadowsocks-server@config
    

    To start shadowsocks proxy, run

    systemctl start shadowsocks-server@config
    

    For status/restart

    systemctl status shadowsocks-server@config
    systemctl restart shadowsocks-server@config
    
  • Install nslookup on ArchLinux

    To install nslookup on ArchLinux, run

    pacman -S dnsutils
  • 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
    

  • Configure OVH Bridge Network from command line

    Configure OVH Bridge Network from command line

    If you have a Proxmox or VmWare ESXi server on OVH network, you need to configure network interface once virtual machine is created.

    First login to OVH, go to IP page. Find the IP address you need to assign to this new VM, create a Virtual MAC. OVH allow 2 type of MAC. If you are using Proxmox, use OVH Mac. For VMWare ESXi, use vmware vmac.

    Once you have Virual Mac. you need to configure it in your VM network interface settings. For Vmware ESXi

    Now login to Virtial Machine, run following commands

    ip link set NETWORK_INTERFACE_HERE up
    ip addr add FO_IP_HERE dev NETWORK_INTERFACE_HERE
    ip route add GW_IP_HERE dev NETWORK_INTERFACE_HERE
    ip route add default via GW_IP_HERE dev NETWORK_INTERFACE_HERE
    

    In above, replace

    NETWORK_INTERFACE_HERE = name of your network interface. This can be found with command “ip link”. Normally it is eth0 or ensXXX.

    FO_IP_HERE = this is the Failover IP you will be using for this Virtual Machine.

    GW_IP_HERE = This is gateway IP. For OVH network, it will be your servers MAIN IP address with last number replaced with 254.

    Here is an actial example.

    ip link set ens192 up
    ip addr add 178.33.35.183 dev ens192
    ip route add 149.202.199.254 dev ens192
    ip route add default via 149.202.199.254 dev ens192
    

    This settings will be lost when you reboot OS. For configuring network interface permanantly, you can do

  • Install iperf3 on ArchLinux

    To install iperf3 on ArchLinux, run

    pacman -S iperf3
    

    To do speed test

    [root@tvmovies1 ~]# iperf3 -c ping.online.net -p 5209
    Connecting to host ping.online.net, port 5209
    [  5] local 163.172.50.206 port 50430 connected to 62.210.18.40 port 5209
    [ ID] Interval           Transfer     Bitrate         Retr  Cwnd
    [  5]   0.00-1.00   sec   282 MBytes  2.36 Gbits/sec    0    720 KBytes       
    [  5]   1.00-2.00   sec   280 MBytes  2.35 Gbits/sec    0    755 KBytes       
    [  5]   2.00-3.00   sec   281 MBytes  2.36 Gbits/sec   11    755 KBytes       
    [  5]   3.00-4.00   sec   280 MBytes  2.35 Gbits/sec    0    758 KBytes       
    [  5]   4.00-5.00   sec   281 MBytes  2.36 Gbits/sec    0    758 KBytes       
    [  5]   5.00-6.00   sec   256 MBytes  2.15 Gbits/sec  1507   42.4 KBytes       
    [  5]   6.00-7.00   sec   115 MBytes   965 Mbits/sec  6917    130 KBytes       
    [  5]   7.00-8.00   sec   114 MBytes   954 Mbits/sec  6643   48.1 KBytes       
    [  5]   8.00-9.00   sec   114 MBytes   954 Mbits/sec  6749    119 KBytes       
    [  5]   9.00-10.00  sec   112 MBytes   944 Mbits/sec  6923   38.2 KBytes       
    - - - - - - - - - - - - - - - - - - - - - - - - -
    [ ID] Interval           Transfer     Bitrate         Retr
    [  5]   0.00-10.00  sec  2.07 GBytes  1.77 Gbits/sec  28750             sender
    [  5]   0.00-10.00  sec  2.06 GBytes  1.77 Gbits/sec                  receiver
    
    iperf Done.
    [root@tvmovies1 ~]# 
    

    Here we do speed test with http://ping.online.net, they run iperf3 server on port 5209

  • Install netdata on ArchLinux

    First update the packages with

    pacman -Syu
    

    Install netdata

    pacman -S netdata
    

    Enable and start netdata

    systemctl enable netdata
    systemctl start netdata
    
  • 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