iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🎉

Changing Debian 12 Server Settings from English to Japanese

に公開

Summary

There are various reasons why you might want to customize an English-language Debian GNU/Linux 12 (Bookworm) environment to your liking, such as when using containers, VMs, or renting a server abroad.

I will record the procedure here.

Introduction

I use a software called incus[1] to manage containers and VMs.

I am documenting the process of setting up a new container with my preferred settings for my future self.

Who this article is for

For those who want to customize an environment where Debian GNU/Linux is already installed to their liking.

How to read this document

You should be able to just pick out and read the parts you need.

Main Content

Outline

I will explain in the following order:

  1. Create the ja_JP.UTF-8 locale
  2. Set the system locale to ja_JP.UTF-8
  3. Set the system local time to Asia/Tokyo
  4. Create a regular user
    • Configure the user to allow sudo

By the way, the reason I haven't included openssh-server is that if you pre-generate keys for openssh-server when creating a template, the same keys will be reused, which is not ideal. Therefore, it's better to install it later.

You could also say I was just too lazy to look up how to regenerate SSH server keys.

Checking and Generating Locales

First, verify whether the Japanese locale has been generated. Check the /etc/locale.gen file. Using root, verify with vi, nano, or a similar editor if the line for ja_JP.UTF-8 is enabled.

To check if it is valid via the command line, you can try running validlocale ja_JP.UTF-8 as root.

Below is an example of checking ja_JP.EUC-JP.

# validlocale ja_JP.EUC-JP
locale 'ja_JP.EUC-JP' not available
ja_JP.EUC-JP EUC-JP

In most cases, there is a # at the beginning of the line, making it a comment. Remove the # at the start of the line to make it an active line.[2]

Run the locale-gen command as root and confirm that ja_JP.UTF-8 is generated.

# locale-gen 
Generating locales (this might take a while)...
  en_US.UTF-8... done
  ja_JP.UTF-8... done
Generation complete.

Locale Settings

Check the current locale settings.

# localectl status
System Locale: LANG=en_US.UTF-8
    VC Keymap: (unset)
   X11 Layout: (unset)

Initially, it should look like the above.

localectl set-locale ja_JP.UTF-8

Run this to set the locale to Japanese.

Alternative Solution

I found a useful alternative for batch processing on 2024-09-26, so I am adding it here.
2024-11-25: This alternative of setting the locale via the command line did not work on Debian 12 running in Incus. For now, I configured it interactively using dpkg-reconfigure locales, but I will investigate this further later.

As mentioned in the references, run the following commands. Since this uses debconf, it is limited to Debian-based systems. Run these with root or equivalent privileges.

echo "locales locales/default_environment_locale select ja_JP.UTF-8" | debconf-set-selections
echo "locales locales/locales_to_be_generated multiselect ja_JP.UTF-8 UTF-8" | debconf-set-selections
dpkg-reconfigure --frontend noninteractive locales

The commands involved are shown below, so as long as the debconf package is installed, you can use them for batch processing.

dpkg -S debconf-set-selections
debconf: /usr/share/man/man1/debconf-set-selections.1.gz
debconf: /usr/bin/debconf-set-selections
dpkg -S dpkg-reconfigure
debconf: /usr/sbin/dpkg-reconfigure
debconf: /usr/share/man/man8/dpkg-reconfigure.8.gz

Time Zone Settings

Check the current time zone with timedatectl status.

To see what time zones are available, check by piping the output of timedatectl list-timezones to less or a similar tool.

timedatectl set-timezone Asia/Tokyo
Use this to set the system to Japan local time. The system clock is assumed to be in UTC.

General User Settings

Create a regular user for daily use with adduser. In my case, I ran adduser yabuki as root.

To allow the newly created regular user to use sudo, edit /etc/sudoers using the visudo command.

The good thing about using visudo is that it will warn you if there is a mistake in the sudoers configuration before you finish.

Reference Documents

I checked the usage of each command and the syntax for sudoers using the man command.

Conclusion

Item Date
Date written 2024-09-22
Date updated 2024-11-25

The above is provided by the author to help assess the freshness of this article.

For the detailed change history, please refer to:
GitHub - yabuki/friendly-potato: zenn-contents

I would appreciate it if you could submit a pull request for typos or other corrections. Whether to accept them will be determined by the diff and the content of the pull request.





脚注
  1. For information about incus, please refer to sources like Episode 824: Trying 'Incus 6.3', which now allows running Docker containers directly, on Ubuntu 24.04 | gihyo.jp. While Docker is also good, I use incus because I was looking for something lightweight and easy to manage with persistent containers. By the way, I found the incus file mount command easier to understand than Docker volumes. Since you can copy configuration files via sshfs, it's more convenient than the cp command used in LXD. ↩︎

  2. You can likely use the ex command to batch the editing process. Please refer to "Using Vim from a shell script" in usr_26 - Vim Japanese Documentation. It is convenient to automate editing by combining the echo command with ex or ed commands. ↩︎

GitHubで編集を提案

Discussion