Contents
1. Installing and configuring the vim editor
Debian has "nano" as the default editor. nano is somewhat difficult to use, and there are few environments where it is used, so we will introduce the procedure for changing the editor to "vim".。
1.1 Check vim package
Debian has vim installed by default, but it is a package called "vim-tiny", which is a less functional version. Let's check the installed vim package.
Debian uses the "dpkg" command to check packages. The "-l" option displays a list of packages.
Since the "dpkg" command as is will show all packages installed on the system, we will use the "grep" command to extract only those packages that contain the string "vim". Execute as follows
1 2 3 |
huong@debian:~$ dpkg -l | grep vim ii vim-common 2:8.2.2434-3+deb11u1 all Vi IMproved - Common files ii vim-tiny 2:8.2.2434-3+deb11u1 amd64 Vi IMproved - enhanced vi editor - compact version |
You can see that only the "vim-tiny" package is installed as shown above.
1.2 Installing the vim package
The "-y" option to the apt install command is an option that automatically confirms the installation.
1 2 3 4 5 6 7 8 9 |
$ su - Password : ←Root user password created during the installation process of Debian 11.3 # apt install -y vim After installation, check the vim package again with the dpkg command # dpkg -l | grep vim ii vim 2:8.2.2434-3+deb11u1 amd64 Vi IMproved - enhanced vi editor ii vim-common 2:8.2.2434-3+deb11u1 all Vi IMproved - Common files ii vim-runtime 2:8.2.2434-3+deb11u1 all Vi IMproved - Runtime files ii vim-tiny 2:8.2.2434-3+deb11u1 amd64 Vi IMproved - enhanced vi editor - compact version |
Vim is installed as shown above.
1.3 Change the editor used by default
Change the default editor to "vim" installed from nano.
To change the default editor, run the command "update-alternatives --set editor".
To change to vim, run the following
1 2 |
# update-alternatives --set editor /usr/bin/vim.basic update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/editor (editor) in manual mode |
If the output looks like the above, the editor has been changed.
1.4 Change vim settings
To allow all users, create a ".vimrc" file in "/root/".
To create a vim environment for each user, create a ".vimrc" file in the user's home directory.
This time, we will create a ".vimrc" file in the root user's home directory "/root/".
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# vi ~/.vimrc "Enables pasting and copying of text 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 " Obtain a backup "The opposite is[ set nobackup ] set backup " Specify the directory from which to obtain backups set backupdir=~/backup " Specify the directory from which to obtain backups set backupdir=~/backup " Number of generations to keep search history set history=50 " 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 "The opposite is[ set nohlsearch ] set hlsearch " Use incremental search "The opposite is [ set noincsearch ] set incsearch " Display line numbers "The opposite is [ set nonumber ] set number " Visualize line breaks ( $ ) and tabs ( ^I ) set list " 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 |
Comment out any unnecessary items above.
1.5 Activation of vim configuration changes
Please log out of the system for the settings to take effect. When you log in to the system again, the above information will be reflected.
2. Network Settings
2.1 Host Name Settings
This section describes cases where the hostname is set during Debian installation, but the hostname is changed for some reason.
Use the "hostnamectl set-hostname" command to set the hostname.
As an example, set "Lepard".
1 |
# hostnamectl set-hostname Lepard |
The result of the configuration can be checked by referring to the "/etc/hostname" file.
1 2 |
# cat /etc/hostname Lepard |
2.2 Set IP address to network interface
The IP address is set to DHCP (dynamic IP address) when Debian 11 is installed, so set a fixed IP address.
Modify the "/etc/network/interfaces" file to set the IP address, and then restart the network interface (ens33 in this case).
The network interface name will vary depending on the environment in which the setup was performed, so check the interface name first.
The command to check network information is "ip addr". Running this command will display the network interface name and IP address information.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
# 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 pfifo_fast state UP group default qlen 1000 link/ether 00:0c:29:f4:87:6c brd ff:ff:ff:ff:ff:ff altname enp2s1 inet 192.168.11.45/24 brd 192.168.11.255 scope global dynamic ens33 valid_lft 171272sec preferred_lft 171272sec inet6 fe80::20c:29ff:fef4:876c/64 scope link valid_lft forever preferred_lft forever |
Here, "ens33" is the "network interface name. lo" is the "local loopback interface" and is not normally used.
2.3 Setting up a static IP address
We proceed assuming the following information necessary for the network configuration and the parameters to be configured this time.
・IP address 192.168.11.83
・subnet mask 255.255.255.0
・default gateway 192.168.11.1
・DNS Server 192.168.11.1
IP addresses are set by modifying the "/etc/network/interfaces" file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# vi /etc/network/interfaces Default values are as follows # The primary network interface allow-hotplug ens33 iface ens33 inet dhcp Change as follows # The primary network interface allow-hotplug ens33 #iface ens33 inet dhcp ←comment-out # network interface settings iface ens33 inet static address 192.168.11.83 netmask 255.255.255.0 gateway 192.168.11.1 dns-nameservers 192.168.11.1 |
2.4 Enable static IP address
1 |
# systemctl restart networking ifup@ens33 |
3. Set server time synchronization
set up "timesyncd".
3.1 Configuration of timesyncd service
The timesyncd service is configured in the file "/etc/systemd/timesyncd.conf". Before changing the file, make a backup copy of the original file.
1 |
# cp -p /etc/systemd/timesyncd.conf /etc/systemd/timesyncd.conf.org |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# vi /etc/systemd/timesyncd.conf Default values are as follows [Time] #NTP= #FallbackNTP=0.debian.pool.ntp.org 1.debian.pool.ntp.org 2.debian.pool.ntp.org 3.debian.pool.ntp.org #RootDistanceMaxSec=5 #PollIntervalMinSec=32 #PollIntervalMaxSec=2048 Changed as follows NTP=ntp.jst.mfeed.ad.jp FallbackNTP=ntp.nict.jp #RootDistanceMaxSec=5 #PollIntervalMinSec=32 #PollIntervalMaxSec=2048 |
3.2 Reflection of timesyncd service settings
1 |
# systemctl restart systemd-timesyncd |
If no error is output, the service has restarted.
Check the time synchronization. The "timedatectl status" command is used to check the time synchronization. Execute the command as follows
1 2 3 4 5 6 7 8 |
# timedatectl status Local time: Sun 2022-10-09 19:22:24 JST Universal time: Sun 2022-10-09 10:22:24 UTC RTC time: Sun 2022-10-09 10:22:25 Time zone: Asia/Tokyo (JST, +0900) System clock synchronized: yes NTP service: active RTC in local TZ: no |
If "System clock synchronized: yes" is displayed, the time is synchronized.
4. Restrict users who can su
In Debian, any user can be changed to the root user with the "su" command in the default configuration.
If multiple users are created on the server, limit the number of users who can execute the su command as much as possible, because if the login information of any one of the users is known, the root user privilege can be taken away with the su command after unauthorized access.
Allow only users belonging to the wheel group to be authorized to execute su.
4.1 Adding users to the wheel group
First, create a wheel group with the following command
1 |
# groupadd wheel |
Run the usermod command to add a user to the wheel group. As an example, let us assume that the user to be added is "lan".
1 |
# usermod -g wheel lan |
Confirm that the wheel group is added to the wheel group using the id command.
1 2 |
# id lan uid=1000(lan) gid=1001(wheel) groups=1001(wheel) |
4.2 Edit configuration file for su command
The configuration file for the su command is /etc/pam.d/su. (around line 15)
1 2 3 4 5 6 7 8 |
# Uncomment this to force users to be a member of group wheel # before they can use `su'. You can also add "group=foo" # to the end of this line if you want to use a group other # than the default "wheel" (but this may have side effect of # denying "root" user, unless she's a member of "foo" or explicitly # permitted earlier by e.g. "sufficient pam_rootok.so"). # (Replaces the `SU_WHEEL_ONLY' option from login.defs) auth required pam_wheel.so ←Uncomment |
The lan user can now transition to root privileges using the "su -" command.
5. Debian Repository Mirror Settings Edit
The repository mirror configuration file is /etc/apt/sources.list, make a copy and edit it.
1 2 3 |
# cd /etc/apt/ # cp sources.list sources.list_back # vi /etc/apt/sources.list |
The file contents
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
#deb cdrom:[Debian GNU/Linux 11.3.0 _Bullseye_ - Official amd64 NETINST 2022 0326-11:22]/ bullseye main deb http://ftp.jp.debian.org/debian/ bullseye main deb-src http://ftp.jp.debian.org/debian/ bullseye main deb http://security.debian.org/debian-security bullseye-security main deb-src http://security.debian.org/debian-security bullseye-security main # bullseye-updates, to get updates before a point release is made; # see https://www.debian.org/doc/manuals/debian-reference/ch02.en.html#_upda tes_and_backports deb http://ftp.jp.debian.org/debian/ bullseye-updates main deb-src http://ftp.jp.debian.org/debian/ bullseye-updates main # This system was installed using small removable media # (e.g. netinst, live or single CD). The matching "deb cdrom" # entries were disabled at the end of the installation process. # For information about how to configure apt package sources, # see the sources.list(5) manual. |
If used in Japan, it should be a mirror with jp.
6. Make the locate command available
To search for a specific file on the entire Linux system, use the find command, but find's options are somewhat confusing.
The locate command can extract all files with a given filename.
Although a database of file and folder names must be created in advance, it has the advantage of being fast and easy to use. The "locate" command can be used here.
6.1 Installing the locate package
1 2 3 |
# apt install -y locate # dpkg -l | grep locate ii locate 4.8.0-1 amd64 maintain and query an index of a directory tree |
6.2 Create database
1 |
# updatedb |
6.3 Running the locate command
As an example, search for all files named "sshd".
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
# locate sshd /etc/pam.d/sshd /etc/ssh/sshd_config /etc/systemd/system/sshd.service /run/sshd /run/sshd.pid /usr/sbin/sshd /usr/share/man/man5/sshd_config.5.gz /usr/share/man/man8/sshd.8.gz /usr/share/openssh/sshd_config /usr/share/openssh/sshd_config.md5sum /usr/share/vim/vim81/syntax/sshdconfig.vim /var/lib/systemd/deb-systemd-helper-enabled/sshd.service /var/lib/ucf/cache/:etc:ssh:sshd_config |
A list of filenames containing sshd is now displayed.
7. Locale Settings
If you have selected Japanese as your locale when installing Debian, you are already in a Japanese environment and do not need to change it.
If your environment is "English locale" and you prefer to use Japanese locale, please do so.
7.1 Check current locale
Check the locale set in the system. Use the "localectl status" command to check the locale.
1 2 3 4 5 |
# localectl status System Locale: LANG=C.UTF-8 VC Keymap: n/a X11 Layout: jp X11 Model: pc105 |
In the above case, "C.UTF-8" is the locale, which means C locale (POSIX locale).
7.2 Changed to Japanese locale
In Debian, a list of locales can be found with the command "localectl list-locales". Run it to see which locales are available on your system.
1 2 3 |
# localectl list-locales C.UTF-8 ja_JP.UTF-8 |
Two locales are displayed. Since "ja_JP.UTF-8" in the displayed results is the locale for Japanese, set the "ja_JP.UTF-8" locale.
To set the locale, use the "localectl set-locale" command. Execute as follows
1 2 3 4 5 6 7 |
# localectl set-locale LANG=ja_JP.UTF-8 # localectl status System Locale: LANG=ja_JP.UTF-8 VC Keymap: n/a X11 Layout: jp X11 Model: pc105 |
We have confirmed that the "ja_JP.UTF-8" locale is set as shown above.
8. Time zone settings
In most cases, the time zone for Debian 11 is set during installation, but if the Japanese time zone "JST" is not specified, it can be changed with the "timedatectl" command.
8.1 Display of current time zone
To check the time zone set on the server, run the "timedatectl status" command
1 2 3 4 5 6 7 8 |
# timedatectl status Local time: Sun 2022-10-09 19:41:56 JST Universal time: Sun 2022-10-09 10:41:56 UTC RTC time: Sun 2022-10-09 10:41:56 Time zone: Asia/Tokyo (JST, +0900) System clock synchronized: yes NTP service: active RTC in local TZ: no |
The time zone is set to "Asia/Tokyo (JST)" as shown above.
8.2 Change time zone to Japan
If it is not "Asia/Tokyo (JST)", you can change the time zone with the "timedatectl set-timezone" command.
1 |
# timedatectl set-timezone Asia/Tokyo |
9. Update system packages
Debian systems installed from the media may contain outdated packages. Debian also uses "apt" to update all packages.
To see only the list of packages to be updated without updating the packages, run the "apt update" command. The command is executed as follows
1 2 |
# apt update # apt upgrade -y |