Click here for "Safe Air Conditioner Repair and Proper Freon Recovery".

Ubuntu Server 22.04 : Initialization

1. Set root password and use SU command

The root user is unavailable in the default Ubuntu configuration because no password is set.
Setting a password for the root user allows transitions using the conventional [su] command.

$ sudo passwd root
[sudo] password for <user名> ← Current user's password
Enter new UNIX password: ← Enter the root user password to be set
Retype new UNIX password: ← Re-entry force
passwd: password updated successfully
$ su -
Password:<Password set above>

2. System Modernization

# apt update
# apt upgrade

3. Make the locate command available

The find command is often used to search for specific files throughout the Linux system, but find is somewhat confusing in specifying options.
The locate command can extract all files with a given filename.

3.1 Installing the locate package

# apt install -y mlocate
Check the package
# dpkg -l | grep mlocate
ii mlocate 1.1.15-1ubuntu2 all transitional dummy package

3.2 Example of executing the locate command

# locate sshd
etc/pam.d/sshd
/etc/ssh/sshd_config
/etc/ssh/sshd_config.d
・・・・
You will see a list of filenames containing sshd as above

4. vim editor settings

Ubuntu has vim installed by default

4.1 Change vim settings

This time, we will create a ".vimrc" file in the root user's home directory "/root/" and configure it to apply to all users.

# vi ~/.vimrc
※Add the following as the contents of the file
set clipboard+=autoselect
" Use vim's own extensions (not compatible with vi)
set nocompatible
" Specify character code
set encoding=utf-8
" Specify file encoding
set fileencodings=utf-8,iso-2022-jp,sjis,euc-jp
" Specify the line feed code to be automatically recognized
set fileformats=unix,dos
" Do not distinguish between upper and lower case letters when searching
set ignorecase
" Mixing capital letters in search terms makes the search case sensitive
set smartcase
" Highlight words matching your search term  
set hlsearch
" Use incremental search (start searching for matching strings at any time while entering search terms)
"The opposite is [setnoincsearch ]
set incsearch
" Display line numbers  The opposite is [ set nonumber ]
set number
" Highlight corresponding parentheses when typing parentheses
set showmatch
" No newlines at the end of files
set binary noeol
" Enable automatic indentation  The opposite is [ noautoindent ]
set autoindent
" Color-coded display by syntax  The opposite is [ syntax off ]
syntax on
" change color of comment text in case of [syntax on]
highlight Comment ctermfg=LightCyan
" Wrap lines by window width  The opposite is [ set nowrap ]
set wrap

5. Network Settings

5.1 Host Name Settings

This procedure is not necessary if the host name was set at the time of Ubuntu installation and the host name is to be used as it is.
To change the hostname, use the "hostnamectl set-hostname" command.
As an example, here we set "ubuntu-10" as the host name。

# hostnamectl set-hostname ubuntu-10
Confirmation of the result of the configuration
# cat /etc/hostname
ubuntu-10

5.2 Set IP address to network interface

This section is not necessary if a fixed IP address is specified during Ubuntu installation.
To change the IP address, modify the " /etc/netplan/00-installer-config.yaml" file and then restart the network interface (ens33 in this environment).
The network interface name will vary depending on the environment in which the setup was performed, so check the interface name first.

Network Information Confirmation
# ip addr
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: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:0c:29:e7:3d:0a brd ff:ff:ff:ff:ff:ff
altname enp2s1
inet 192.168.11.83/24 brd 192.168.11.255 scope global ens33
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fee7:3d0a/64 scope link
valid_lft forever preferred_lft forever

ens33:  network interface name
192.168.11.83 : IP address

5.2.1 Setting up a static IP address
For this example, we will fix the IP address to 192.168.11.63.
The required network information is as follows, which is reflected in the configuration file.
IP address : 192.168.11.63/24
default gateway : 192.168.11.1
name server : 192.168.11.1
IP address configuration is done by modifying the file " /etc/netplan/00-installer-config.yaml".

Default settings should be disabled and backed up.
# mv /etc/netplan/00-installer-config.yaml /etc/netplan/00-installer-config.yaml.bak
Create a new installer configuration file
# vi /etc/netplan/01-netcfg.yaml
# This is the network config written by 'subiquity'
network:
ethernets:
ens33:
addresses:
- 192.168.11.63/24
gateway4: 192.168.11.1
nameservers:
addresses:
- 192.168.11.1
version: 2

# Reflect settings
# netplan applye

5.2.2 Disabling IPv6

# echo "net.ipv6.conf.all.disable_ipv6 = 1" >> /etc/sysctl.conf
# sysctl -p
net.ipv6.conf.all.disable_ipv6 = 1

6. Configure server time synchronization

Configure "timesyncd", a service that automatically adjusts the server time.

6.1Configuration of timesyncd service

Before changing a file, make a backup copy of the original file
# cp -p /etc/systemd/timesyncd.conf /etc/systemd/timesyncd.conf.org
# vi /etc/systemd/timesyncd.conf
[Time] #NTP=
#FallbackNTP=ntp.ubuntu.com
#RootDistanceMaxSec=5
#PollIntervalMinSec=32
#PollIntervalMaxSec=2048 [Time] ↓ change
[Time] NTP=ntp.jst.mfeed.ad.jp     ← add
FallbackNTP=ntp.nict.jp       ← add
#RootDistanceMaxSec=5
#PollIntervalMinSec=32
#PollIntervalMaxSec=2048

6.2Reflection of timesyncd service settings

# systemctl restart systemd-timesyncd

Confirmation of time synchronization
# timedatectl status
Local time: Wed 2022-05-18 00:23:27 UTC
Universal time: Wed 2022-05-18 00:23:27 UTC
RTC time: Wed 2022-05-18 00:23:26
Time zone: Etc/UTC (UTC, +0000)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no

If "System clock synchronized: yes" is displayed, the time is synchronized.

6.3 Set time zone to Japan

In the above, Time zone: Etc/UTC (UTC, +0000), so it matches Japan (Asia/Tokyo).

# timedatectl set-timezone Asia/Tokyo
# timedatectl status
Local time: Wed 2022-05-18 09:25:50 JST
Universal time: Wed 2022-05-18 00:25:50 UTC
RTC time: Wed 2022-05-18 00:25:50
Time zone: Asia/Tokyo (JST, +0900)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no

As above, it is in Japan.

タイトルとURLをコピーしました