Installing a Minimal Server for Ubuntu 18.04 LTS (Bionic Beaver) (page 2)

botond published 2019/07/02, k - 17:41 time

2. page content

 

Continuation

Az previous page we have completed all the steps of the installer and now we are going to do some command line setup to get this minimal server ready for future server installation.

 

 

First login

After restarting the machine, first enter the console:

Ubuntu 18.04 LTS (Bionic Beaver) - Login

After logging in, we get quite a few information, including the machine IP addresses will be displayed, but it will be important later. The first thing we need to do now is to restart the machine because the system has some important settings in the background when you first start up:

Ubuntu 18.04 LTS (Bionic Beaver) - Restart Required

As you can see there are 80 upgradeable packages, as we did not use the small netinstall installer, which picks up the fresh packages during installation.

First, reboot your system as prompted by the system:

sudo reboot

You will be prompted for the password of the user you provided during installation and the system will reboot.

 

Package repository and update packages

After the machine restarts, log in with your user and get root access:

sudo su

Then update the package store our database and packages in a way known on Debian:

apt-get update
apt-get upgrade

The update will start:

Ubuntu 18.04 LTS (Bionic Beaver) - Update Packages

I'm about to perform 36 MB package updates. Select Yes here.

During the upgrade, there will also be a dialog asking if you want to manually approve individual services restarts, or auto-restart all daemon in one step:

Ubuntu 18.04 LTS (Bionic Beaver) - Restart Services together

So here is a good idea Yes option to do it all at once.

Now that our packages are up to date, we can make the necessary adjustments.

 

 

Enable Root User (Optional)

By default, Ubuntu login with the root user is disabled. Developers and the Ubuntu community strongly recommend direct access to the root user. Instead, they recommend using sudo when you need root privileges to perform a task. However, root access is allowed, but it is only used when it is really needed!

If you want to enable root login anyway, first log in as a regular user and then enter a password for the root user:

sudo passwd root

Then the sudo command first asks for the password of our plain user, and then the passwd command twice the new password for the root user. After that, we can log in directly as root, for example on the console.

If you want to use the sudo command without a password, you can find out more here.

 

Remote SSH login

Using a machine running in VirtualBox in console mode is a bit inconvenient in my opinion. Eg clipboard, mouse handling, etc. Therefore, I personally open a terminal window on my desktop (Debian) machine and log in from there SSHbecause I have more control over everything in my usual terminal window. Of course, those who use Windows can log in from there, for example Putty help. But those who qualify for the VirtualBox host console may remain in it.

The first time I logged in, I wrote that the IP address of the machine would appear. Well, those who choose SSH will still be able to log on to the host machine using this IP address, except for the username you specified during installation. For example, about Linux:

ssh linuxportal@192.168.1.104
The IP address may be different for each network. For example, the addresses I had before that were reserved for desktop, laptop, etc., so it was my first free address. So everyone uses his or her own address, for example. the router.
In addition, it is important that the host machine can only access our newly installed guest machine if the In VirtualBox for networks, we have set up Bridge mode for our network card.

If all goes well, the first time you log in to SSH, as is already well known, you first add a new digital fingerprint, which is Yes we need to confirm:

Ubuntu 18.04 LTS (Bionic Beaver) - SSH Login - Add New Digital Fingerprint

So here we have added a digital fingerprint associated with the IP address of the guest machine to the host machine, which it will not ask for more than once.

From here I continue to work in the terminal, but it can also be solved in the console, only there I think it is more inconvenient.

 

Configure Nano (Optional)

A GNU nano word processor I think is the best word processor when working in a terminal. The LTS (Bionic Beaver) version of Ubuntu 18.04 is included by default, so you don't have to install it anymore, you just need to do a little fine-tuning to make it even more convenient to use.

You can do this as a plain user and as root, so that your favorite editor works the same for both. Create the nano configuration file in the user's home directory:

nano ~/.nanorc

Here are some settings:

set tabsize 4
set smooth
set mouse
set const

Line items have the following meaning:

  • set tabsize 4: Tab size 4 characters. By default, 8 characters, which is too much. 4 is used in most places.
  • set smooth: Fine scrolling. As a result, scrolling is done line by line, making it easier to scroll over larger files.
  • set mouse: Enables mouse operations. For example, positioning the cursor with the mouse, etc.
  • set const: Display row, column, character position information. This is also useful if, for example, x is used in a specific config file. a setting must be made in a row. This makes it easy to navigate to the right line.

Of course still nano has a lot of settingsso everyone can spice it up to their liking.

After saving and exiting, the next time you start nano, the settings will take effect.

 

 

Set up a network

Ubuntu installer DHCPconfigured the network, which results in dynamic address assignment. A server requires a static IP address to operate. If you build your server on a home developer or test environment, this is not important, in which case it is enough to set a fixed IP address on your router to the machine's MAC address, and you can skip this section. However, if you are creating a server for live use, you will need to configure Ubuntu (also) with a fixed IP address, which can be done as follows.

Configure Netplan

In Ubuntu 18.04, the network is configured using Netplan, previously known on Debian systems. / etc / network / interfaces configuration file is no longer in use. If we look at it, we will find just that:

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

There is a way to restore the old network manager, but why make it complicated if you can configure it in Netplan. Enter the Netplan config directory as root:

cd /etc/netplan

We will find a configuration file here, open it with nano:

nano 50-cloud-init.yaml

This contains the following content:

# This file is generated from information provided by
# the datasource.  Changes to it will not persist across an instance.
# To disable cloud-init's network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
    ethernets:
        enp0s3:
            dhcp4: true
    version: 2

Comment on the network section to keep the original settings, and then add your own static IP address settings to make the file look like this:

# This file is generated from information provided by
# the datasource.  Changes to it will not persist across an instance.
# To disable cloud-init's network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
#network:
#    ethernets:
#        enp0s3:
#            dhcp4: true
#    version: 2

network:
    version: 2
    renderer: networkd
    ethernets:
        enp0s3:
            dhcp4: no
            dhcp6: no
            addresses: [192.168.1.125/24]
            gateway4: 192.168.1.1
            nameservers:
                addresses: [8.8.8.8,8.8.4.4]
Important!
Pay attention to the indents here, because this is the only way the system will interpret the yaml file. Tabs are not allowed, only spaces can be used for indents. I used the "standard" 4-character indent in the configuration file so it is clearer.
The configuration I present may differ elsewhere. For example, the name of the network device (enp0s3) and the gateway IP address (gateway4 address) may be different on another machine or network. Check these (print the name of the network device when you log in, and the gateway address, for example, ip r | grep default or the route can be queried with one of the commands).
Also, the IP address of 192.168.1.125 that I specify is a special setting, so let's set it to the appropriate address for your network and for it (I set Debian virtual machines to IP address 120 and Ubuntu systems to 125). . In the case of a live server (eg VPS or leased server), we use the static IP address provided for the subscription.
For name servers, the Google's public name servers i gave it, it works everywhere.

Save and exit the editor.

Then the netplan generate command from the yaml file creates a configuration that can be understood by the background network management system. So let's run it (as root):

netplan generate

If the command finds a tab somewhere in the file where the indent is, throw this error:

/etc/netplan/50-cloud-init.yaml:13:1: Invalid YAML: tabs are not allowed for indent:
        version: 2
^

And if we didn't use indentation somewhere, it throws the following error:

/etc/netplan/50-cloud-init.yaml:16:15: Error in network definition: expected mapping (check indentation)
        enp0s3:
               ^

If all goes well, it will not give any output.

Then run the following command to apply the changes:

netplan apply

Set host name

A during installation for the hostname section it was not possible to complete FQDN name, but only the hostname itself could be set. In a hurry, I entered the name "linuxportal" there. But now that I rethink this, I set it differently. Let the full hostname of this machine be say "ubuntu18.linuxportal.vm" This refers to the system on the machine (which will be perfect for future server installations), the linux portal server series, and that it is a virtual machine. Of course, everyone here now uses their own appropriate FQDN name to model this. So the next part here will be perfect for making a full name change. So if someone downloads this server, they can change it to their own hostname accordingly.

First, open a / Etc / hosts file:

nano /etc/hosts

It currently has:

127.0.0.1       localhost.localdomain   localhost
::1             localhost6.localdomain6 localhost6

# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

Expand it as follows (everyone uses their own name and the IP address used above):

127.0.0.1       localhost.localdomain   localhost
192.168.1.125   ubuntu18.linuxportal.vm   ubuntu18
::1             localhost6.localdomain6 localhost6

# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

Save and then open a /etc/cloud/cloud.cfg file:

nano /etc/cloud/cloud.cfg

Right at the beginning of this we find the following line:

[...]
preserve_hostname: false
[...]

Change this to "true" and save it.

This setting is required for Live ISO installers that include cloud server services. Without this, the hostname will revert to the previous setting after the system is restarted.

Then set the host name in the / etc / hostname file (without the domain name). To do this, run the following commands:

echo ubuntu18 > /etc/hostname
hostname ubuntu18
The first command sets the host name to the configuration file. This is read when the system is restarted. The second command sets the host name for this session so that you do not have to restart the machine now.

Then we can check our short and full hostnames, which will remain after restart:

Ubuntu 18.04 LTS (Bionic Beaver) - Verify host name

 

 

Extras

Without wishing to be exhaustive, I will list here a few settings that are not mandatory, but if we make them, we can make the work in the terminal with them more comfortable.

Bash command line extension

A Bash Command Line Addition, also known as Bash completion let us know the Tab key to type the desired commands or filenames faster. I will write more about this in another article, here the point is that for the root user, the programmable Bash plugin is not enabled by default, but only the basic plugin, which means that it can only add commands and filenames. However, many commands may require a programmed addition.

This feature is available on the system already pre-installed bash completion package, just need to be enabled. To do this, open in the root directory .bashrc file:

sudo nano ~/.bashrc

Then scroll to the bottom where we see this section:

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
#if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
#    . /etc/bash_completion
#fi

Here, take the comment from the last three lines, as I have highlighted in red.

Save and then source the .bashrc file to take effect:

source .bashrc

vagy

. .bashrc

commands.

From here, for example, if you enter, say systemctl and then press two Tab , you will already have listed the other options for this command:

Ubuntu 18.04 LTS (Bionic Beaver) - Bash command line extension

Configuring aliases

There are some alias commands configured, but I will change this a little bit as follows (this can be done for the regular user and for the root):

nano ~/.bashrc
[...]
# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
    test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
    alias ls='ls --color=auto'

    export LS_OPTIONS='--color=auto --group-directories-first'

    #alias dir='dir --color=auto'
    #alias vdir='vdir --color=auto'

    alias grep='grep --color=auto'
    alias fgrep='fgrep --color=auto'
    alias egrep='egrep --color=auto'
fi

# colored GCC warnings and errors
#export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'

# some more ls aliases
#alias ll='ls -alF'
#alias la='ls -A'
#alias l='ls -CF'

# Saját ls aliasok
alias ls='ls $LS_OPTIONS'
alias ll='ls $LS_OPTIONS -l'
alias l='ls $LS_OPTIONS -lAh'
[...]

I added one at the top of the .bashrc detail export LS_OPTIONS starting line with which I set common switches for my own ls aliases below. THE --group-first-directories a very useful one ls switch to list the directories in advance so you can get a much clearer list of directories.

And at the bottom of the detail, I commented on the factory ls aliases and added my own instead. Of these, I use the most recent one, which runs the ls command by the "l" command, which inherits the following switches:

  • --color = auto: Use color output.
  • --group-first-directories: Pre-listing of the libraries mentioned above.
  • -l: Detailed list mode
  • -THE: It also lists the hidden files, but omits the root directory (.) And parent directory (..) from the directories (in the long run I find it annoying, many and .. at the beginning of the lists).
  • h: "Human-readable", that is to divide the file size into bytes instead of bytes into Kb, Mb, Gb. This makes the file size much easier to read.

Of course, everyone can customize the whole thing according to their own needs, so I get used to it, so it's convenient for me to use.

I've written about using the color ls command before in this description, so there are still opportunities.

 

 

Color root prompt

By default the color prompt is turned on for the normal user, but not for the root user. To enable it, log in as root and then open the .bashrc file:

nano ~/.bashrc

Here (in the 39 line of the factory file) you will find one of the following options:

#force_color_prompt=yes

Let's take a comment from this and save it.

Then source the root .bashrc file:

. ~/.bashrc

And then the prompt changed color.

About using the color prompt in this description we can find out more.

 

Download virtual machine

The finished virtual machine Download from here.

 

Conclusion

So this would be a minimal server installation for Ubuntu 18.04 LTS (Bionic Beaver), which will be an excellent basis for installing later LAMP or perfect servers. We have set everything up so that we can work on the server in the future.

 

What's next?

Creating a minimal server is a great step one Install v18.04 on the Ubuntu 1.0 LTS (Bionic Beaver) LAMP Server.

It is also designed for Debian LAMP servers or more complex perfect servers also recommend for study.

 

 

Navigation

This description consists of several pages: