Sunday, May 10, 2020

Install Ubuntu 20.04 Server

The server version of Ubuntu had previously been tuned for server-oriented workloads. This is reportedly no longer the case, so a primary difference between Ubuntu 20 server and desktop is that server lacks a graphical user interface.

Download an image from the Ubuntu releases page. Most everything is 64 bit. Note that "AMD" means it works on the AMD and Intel instruction sets. You can use the AMD64 image on a modern Intel CPU.

Burn the image to a DVD or other mountable storage. Boot the machine from the storage. This install will use hard-wired Ethernet and a static IP address. If you have a real (typically non-consumer internet service) domain name, use that as the "search domain".







































This is a server install, so maybe you do not want "games" in your search path. Backup the "environment" file then remove the games directory from the search path.
$ sudo mv /etc/environment /etc/environment.orig
$ sudo vi /etc/environment
$ cat /etc/environment
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"


Modify the shell login files in your home directory.
$ cd ~
$ cp -p .bashrc .bashrc.orig
$ mv .profile .profile.orig
$ mv .bashrc .bash_profile

Remove colorization by setting TERM environment variable in .bash_profile.
$ echo $TERM
xterm-256color
$ export TERM=xterm-mono

Edit .bash_profile and put in a bit of color to the command prompt variable PS1.
$ grep 033 ~/.bash_profile
PS1='\[\033[01;32m\]\u@\h\[\033[00m\] \w \$ '


Put the present working directory at the end of the PATH variable. Add this to file .bash_profile.

export PATH=$PATH:.
Remove shell's suggestions for a mis-typed command. Add this to file .bash_profile.
unset command_not_found_handle

Then "source" the login files or simply log out and log in again.
$ ./.bash_profile


Get familiar with the install and the machine.
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04 LTS
Release:        20.04
Codename:       focal
 


$ uname -a
Linux d990 5.4
.0-26-generic #30-Ubuntu SMP Mon Apr 20 16:58:30 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
 

$ lspci
00:00.0 Host bridge: Intel Corporation 2nd Generation Core Processor Family DRAM Controller (rev 09)
00:02.0 VGA compatible controller: Intel Corporation 2nd Generation Core Processor Family Integrated Graphics Controller (rev 09)
00:16.0 Communication controller: Intel Corporation 6 Series/C200 Series Chipset Family MEI Controller #1 (rev 04)
00:16.3 Serial controller: Intel Corporation 6 Series/C200 Series Chipset Family KT Controller (rev 04)
00:19.0 Ethernet controller: Intel Corporation 82579LM Gigabit Network Connection (Lewisville) (rev 04)
00:1a.0 USB controller: Intel Corporation 6 Series/C200 Series Chipset Family USB Enhanced Host Controller #2 (rev 04)
00:1b.0 Audio device: Intel Corporation 6 Series/C200 Series Chipset Family High Definition Audio Controller (rev 04)
00:1c.0 PCI bridge: Intel Corporation 6 Series/C200 Series Chipset Family PCI Express Root Port 1 (rev b4)
00:1c.2 PCI bridge: Intel Corporation 6 Series/C200 Series Chipset Family PCI Express Root Port 3 (rev b4)
00:1d.0 USB controller: Intel Corporation 6 Series/C200 Series Chipset Family USB Enhanced Host Controller #1 (rev 04)
00:1e.0 PCI bridge: Intel Corporation 82801 PCI Bridge (rev a4)
00:1f.0 ISA bridge: Intel Corporation Q67 Express Chipset LPC Controller (rev 04)
00:1f.2 RAID bus controller: Intel Corporation SATA Controller [RAID mode] (rev 04)
00:1f.3 SMBus: Intel Corporation 6 Series/C200 Series Chipset Family SMBus Controller (rev 04)
 

$ df -k
Filesystem      1K-blocks    Used  Available Use% Mounted on
udev              8093172       0    8093172   0% /dev
tmpfs             1627360    1204    1626156   1% /run
/dev/sda2      1921800384 9591096 1814517336   1% /
tmpfs             8136796       0    8136796   0% /dev/shm
tmpfs                5120       0       5120   0% /run/lock
tmpfs             8136796       0    8136796   0% /sys/fs/cgroup
/dev/loop0          27776   27776          0 100% /snap/snapd/7264
/dev/loop1          56320   56320          0 100% /snap/core18/1705
/dev/loop2          70656   70656          0 100% /snap/lxd/14804
tmpfs             1627356       0    1627356   0% /run/user/1000


Familiarize yourself with the network configuration.
$ ls -l /etc/netplan
total 4
-rw-r--r-- 1 root root 280 May 10 00:03 00-installer-config.yaml

$ cat /etc/netplan/00-installer-config.yaml
# This is the network config written by 'subiquity'
network:
  ethernets:
    enp0s25:
      addresses:
      - 192.168.0.9/24
      gateway4: 192.168.0.1
      nameservers:
        addresses:
        - 1.1.1.1
        - 8.8.8.8
        search:
        - duckdns.org
  version: 2



Look at the syslog.
$ sudo tail /var/log/syslog

Look at the running processes, then look at running services.
$ ps -ef | more
$ systemctl list-units --all --type=service --no-pager

Let's remove a service we don't want automatically started, and one we don't need.
$ sudo systemctl stop rsync
$ sudo systemctl disable rsync

$ systemctl status vgauth
● vgauth.service - Authentication service for virtual machines hosted on VMware
     Loaded: loaded (/lib/systemd/system/vgauth.service; enabled; vendor preset: enabled)
     Active: inactive (dead)
  Condition: start condition failed at Sun 2020-05-10 00:16:27 UTC; 2h 30min ago
       Docs: http://github.com/vmware/open-vm-tools

May 10 00:16:27 d990 systemd[1]: Condition check resulted in Authentication service for virtual machines hosted on VMware being skipped.


$ sudo systemctl stop vgauth
$ sudo systemctl disable vgauth

$ systemctl status open-vm-tools
● open-vm-tools.service - Service for virtual machines hosted on VMware
     Loaded: loaded (/lib/systemd/system/open-vm-tools.service; enabled; vendor preset: enabled)
     Active: inactive (dead)
  Condition: start condition failed at Sun 2020-05-10 02:56:23 UTC; 3min 54s ago
       Docs: http://open-vm-tools.sourceforge.net/about.php

May 10 02:56:23 d990 systemd[1]: Condition check resulted in Service for virtual machines hosted on VMware being skipped.
 

$ sudo systemctl stop open-vm-tools
[sudo] password for install:
 

$ sudo systemctl disable open-vm-tools
Synchronizing state of open-vm-tools.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install disable open-vm-tools
Removed /etc/systemd/system/multi-user.target.wants/open-vm-tools.service.
 

$ systemctl status open-vm-tools
● open-vm-tools.service - Service for virtual machines hosted on VMware
     Loaded: loaded (/lib/systemd/system/open-vm-tools.service; indirect; vendor preset: enabled)
     Active: inactive (dead)
       Docs: http://open-vm-tools.sourceforge.net/about.php

May 10 02:56:23 d990 systemd[1]: Condition check resulted in Service for virtual machines hosted on VMware being skipped.


This is a server machine, so we don't need this process attaching to a sound card.
$ apt list pulseaudio
Listing... Done
pulseaudio/focal-updates 1:13.99.1-1ubuntu3.5 amd64 [upgradable from: 1:13.99.1-1ubuntu3.3]
N: There are 3 additional versions. Please use the '-a' switch to see them.
$ sudo apt remove pulseaudio

 
Since this is a server install, the majority of the time it will be accessed remotely. A person using an X display may want to work with images, so install an image viewer such as eog.
$ sudo apt install eog


Disable printing of Ubuntu newswire during shell logon.
$ sudo chmod -x /etc/update-motd.d/50-motd-news

Note the firewall is not active.
$ sudo ufw status
Status: inactive


Install software updates. You may need to reboot the machine to apply all software updates.
$ sudo apt update
$ sudo apt upgrade
$ sudo systemctl reboot

Familiarize yourself with users and groups.
$ cat /etc/passwd
$ cat /etc/group

Put in users and groups.
$ sudo addgroup minecrft
Adding group `minecrft' (GID 1001) ...
Done.
$ sudo adduser minec --ingroup minecrft
Adding user `minec' ...
Adding new user `minec' (1001) with group `minecrft' ...


On a consumer-type internet connection, you may want to configure a dynamic DNS service such as DuckDNS. Create the user, get your information from duckdns.org, then configure software.
$ sudo addgroup duckdns
$ sudo adduser duckdns --ingroup duckdns
Read this to configure the software and crontab entry for duckdns.


Let's change the time zone to Amsterdam.
$ cat /etc/timezone
Etc/UTC
$ timedatectl
               Local time: Sun 2020-05-10 19:12:56 UTC
           Universal time: Sun 2020-05-10 19:12:56 UTC
                 RTC time: Sun 2020-05-10 19:12:56
                Time zone: Etc/UTC (UTC, +0000)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no

$ timedatectl list-timezones | grep -i ams
Europe/Amsterdam
 

$ sudo timedatectl set-timezone Europe/Amsterdam
 

$ cat /etc/timezone
Europe/Amsterdam

$ timedatectl
               Local time: Sun 2020-05-10 21:14:02 CEST
           Universal time: Sun 2020-05-10 19:14:02 UTC
                 RTC time: Sun 2020-05-10 19:14:02
                Time zone: Europe/Amsterdam (CEST, +0200)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no


 

While we could try to disable the cloud initialization with
$ touch /etc/cloud/cloud-init-disabled
Let's remove it.
$ sudo apt remove cloud-init


Optionally, install X server.
$ sudo apt install tightvncserver
$ sudo apt install xterm
Then configure your .Xresources file.


Optionally, install javascript runtime via apt.
$ sudo apt install nodejs
$  which node
/usr/bin/nodejs
$ nodejs --version
v10.19.0

$ sudo apt install chromium-browser
$ which chromium-browser
/usr/bin/chromium-browser

Optionally, upgrade the node software.
$ curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
$ sudo apt install nodejs
$ which node
/usr/bin/node
$ node -v
v12.16.3
$ npm -v
6.14.4



Anyone editing files with vim (vi is typically vim) may want to learn the basics of the .vimrc startup file.
$ cat ~/.vimrc
syntax off
set showmatch
set hlsearch
set matchpairs+=<:>,(:),{:},[:]

:nmap <F1> <nop>


For a graphical editor, install nedit.
$ sudo apt install nedit


Familiarize yourself with memory and disk space, network interfaces and networking, and how the machine is running.  Review the output from the following commands.
Since ifconfig is deprecated, use the ip command. Instead of traceroute, use the mtr command.
$ free -m
$ df -k
$ sudo lshw


$ landscape-sysinfo
$ top
$ htop


$ ip a
$ mtr wunderground.com 

__________________________________________________________

Update of this blog post with more readable explanation of network settings to be used during install from the console. These examples use IP address 192.168.0.6.
















$ ls -l /etc/netplan
total 4
-rw-r--r-- 1 root root 260 Oct 16 21:13 00-installer-config.yaml

$ cat /etc/netplan/*
# This is the network config written by 'subiquity'
network:
  ethernets:
    enp5s0:
      addresses:
      - 192.168.0.6/24
      gateway4: 192.168.0.1
      nameservers:
        addresses:
        - 1.1.1.1
        - 8.8.8.8
        search: []
  version: 2

$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> 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: enp5s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether bc:30:5b:e7:a4:f9 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.6/24 brd 192.168.0.255 scope global enp5s0
       valid_lft forever preferred_lft forever
    inet6 fe80::be30:5bff:fee7:a4f9/64 scope link
       valid_lft forever preferred_lft forever

Sunday, April 26, 2020

Install Apache On Ubuntu Linux

Install the Apache web server on Ubuntu Linux. You will need to be able to install software and start services, so this example uses a Linux account with full sudo. In this example the Linux user name is "testuser".

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.4 LTS
Release:        18.04
Codename:       bionic


$ hostname -I
192.168.0.9


$ sudo ufw status
Status: inactive


# Update package list and install Apache.

$ sudo apt update
...
Fetched 2,854 kB in 2s (1,395 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
All packages are up to date.

$ sudo apt install apache2
...
Created symlink /etc/systemd/system/multi-user.target.wants/apache2.service → /lib/systemd/system/apache2.service.
Created symlink /etc/systemd/system/multi-user.target.wants/apache-htcacheclean.service → /lib/systemd/system/apache-htcacheclean.service.
...

# Note the screen output shows symlinks in the configuration directories for the system services.
 

# Let's see what was is running.
$ systemctl status apache2.service
● apache2.service - The Apache HTTP Server
   Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
  Drop-In: /lib/systemd/system/apache2.service.d
           └─apache2-systemd.conf
   Active: active (running) since Sun 2020-04-26 12:08:28 MDT; 2min 6s ago
 Main PID: 29916 (apache2)
    Tasks: 55 (limit: 4915)
   CGroup: /system.slice/apache2.service
           ├─29916 /usr/sbin/apache2 -k start
           ├─29918 /usr/sbin/apache2 -k start
           └─29919 /usr/sbin/apache2 -k start



# Use a web browser to go to the machine name or IP address.
# Earlier you found the IP address by typing "hostname -I".



# It is kind of the developers and package maintainers to put instructions on the home page! 

# Let's look at the index.html file.
$ cd /var/www/html
$ ls -l
total 12
-rw-r--r-- 1 root root 10918 Apr 26 12:08 index.html

# Being owned by root, we can guess an "apache" unix logon was not created.
$ grep apa /etc/passwd
# Nothing found. Also look at last line of /etc/passwd for a new entry.
$ tail -1 /etc/passwd

# Since software often has errors, bugs, and security holes, an attacker may exploit those
# holes and possibly gain access as the user which is running the software.
# The apache software is being run as root. It had better be perfect software!
# Let's look further.

$ ps -ef | grep apache
root     29916     1  0 12:08 ?        00:00:00 /usr/sbin/apache2 -k start
www-data 29918 29916  0 12:08 ?        00:00:00 /usr/sbin/apache2 -k start
www-data 29919 29916  0 12:08 ?        00:00:00 /usr/sbin/apache2


# Processes are running both as root and as the pre-existing unix logon www-data.

# Let's see if www-data is a less-privileged account than root
$ groups www-data
www-data : www-data
$ sudo grep www /etc/sudoers

# No output from grep, so it looks like www-data doesn't have sudo. This is good.
# To open a listening connection on a "low numbered port", you typically need to be root.
# Maybe that is why part of the web server is started as root. This is something to further explore.

# For now, let's change the static web page served from the file index.html.
$ cd /var/www/html
$ ls -l
total 12
-rw-r--r-- 1 root root 10918 Apr 26 12:08 index.html
$ sudo cp index.html index.html.orig
$ ls -l
total 24
-rw-r--r-- 1 root root 10918 Apr 26 12:08 index.html
-rw-r--r-- 1 root root 10918 Apr 26 12:29 index.html.orig


# Edit the file and add some text.  When editing the file, search for "welcome" and change the text.
$ sudo vi index.html
# In the "content_section_text", you may want to add a new paragraph tags and a couple lines such as:
<p>
“I'm a great believer in luck, and I find the harder I work the more I have of it.”
<a href="https://plato.stanford.edu/entries/jefferson">Thomas Jefferson</a>
</p>

# Reload your web browser to see your changes.



# Verify that systemctl is set up properly to start and stop the web server.
$ sudo systemctl stop apache2.service
$ ps -ef|grep apac
testuser       32236 28823  0 14:58 pts/0    00:00:00 grep apac


$ sudo systemctl start apache2.service
$ ps -ef | grep apac
root     32262     1  0 14:58 ?        00:00:00 /usr/sbin/apache2 -k start
www-data 32264 32262  0 14:58 ?        00:00:00 /usr/sbin/apache2 -k start
www-data 32265 32262  0 14:58 ?        00:00:00 /usr/sbin/apache2 -k start
testuser       32327 28823  0 14:58 pts/0    00:00:00 grep apac

$ systemctl status apache2.service
● apache2.service - The Apache HTTP Server
   Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
  Drop-In: /lib/systemd/system/apache2.service.d
           └─apache2-systemd.conf
   Active: active (running) since Sun 2020-04-26 14:58:53 MDT; 17s ago
  Process: 32214 ExecStop=/usr/sbin/apachectl stop (code=exited, status=0/SUCCESS)
  Process: 32242 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
 Main PID: 32262 (apache2)
    Tasks: 55 (limit: 4915)
   CGroup: /system.slice/apache2.service
           ├─32262 /usr/sbin/apache2 -k start
           ├─32264 /usr/sbin/apache2 -k start
           └─32265 /usr/sbin/apache2 -k start

If you run the firewall, remember to allow incoming pages to apache webserver.
$ sudo ufw enable
$ sudo ufw allow www

Saturday, April 18, 2020

Install Raspbian on Raspberry Pi B+

This will guide you through installation and configuration of a Raspberry Pi B+ with the Raspbian operating system so the device will be accessible on your network. Readily available for around $35, the Raspberry Pi ecosystem is fast-becoming a hobbyist workhorse.


Download Raspbian zip file from www.raspberrypi.org/downloads/raspbian. This example uses "Raspbian Buster with desktop" of February 2020.

Download the Etcher program from www.balena.io/etcher.  Etcher will write the OS zip file image to the SD card.

Insert an 8 GB (or more) microSD card in to the card reader on your Windows PC. This example uses a 32 GB card. In Windows Explorer you should see the SD card.
















Use the Etcher program to write the zip file OS image to the SD card.
 






























After writing the image, the SD card will be unmounted. Physically eject the card from your PC, then reinsert it. Determine the drive letter by looking in File Explorer.
















Let's tell the OS image to allow ssh login. Press the Windows Start button, type
cmd
and start the Command Prompt application.
In the command prompt, go to the drive letter of the SD card. In this example, type
F:

























Create a zero length file named ssh. In the command prompt, type
type nul > ssh



























If you will use a hard-wired ethernet connection from the device to your router, you will not need to configure wifi. To configure wifi, create a file named "wpa_supplicant.conf" with your wifi connection information. The file should only have the suffix ".conf" and the contents should not have Windows-like newline characters. It is important that newline characters are not added to this file. It should be a plain text file. Add the following to the wpa_supplicant.conf file.
country=US
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
scan_ssid=1
ssid="yourWifiSsid"
psk="yourWifiPassword"
}


Type exit to leave the command prompt.

In Windows File Explorer, right-click on the drive and choose EJECT. Physically eject the SD card from the PC.

Plug in the microSD card to the device, and insert the power connector cord in to the device. Don't yet plug it in to power.

Open your router configuration page, and look for the area which shows the current connections. You will looking for either a new DHCP client or a new MAC address. Now that you have opened your router configuration to the appropriate page, plug in the wall power for the device and turn on the power  switch.
Watch the router page for a new connection. If using wifi and it doesn't connect to the router, use the ethernet cable method. Note the IP address.


















Press the Windows Start button and open a command prompt. In the Windows command prompt, connect to the device using the IP address as seen in your router.
ssh pi@192.168.1.101
Accept the key fingerprint warning by typing yes.
The password is
raspberry

You should be logged in. Change the password.
$ passwd

















Modify settings such as locale language, host name, and maybe enable VNC. Start the handy configuration tool. I changed the locale and the host name.
$ sudo raspi-config

If wifi didn't work or you want to enable it, become root and edit the file.
$ sudo su
$ sudo vi /etc/wpa_supplicant/wpa_supplicant.conf


Reboot the device.
$ sudo reboot

The router page will show the new host name.

















For installation of an operating system on bare hardware, this was a smooth and pleasant experience. The teams who put together the custom OS and configuration tools have done superb!

Another good guide for how to install Raspbian OS is at Tom's Hardware.