One of the benefits of using Alpine Linux is its flexibility and customizability, which allows users to tailor the system to their specific needs.
Setting the timezone
Check the current timezone
|
|
Timezone setting
|
|
Which timezone are you in? (’?’ for list) [UTC] Asia/Hong_Kong
Suppose you want to use the
Asia/
timezone andHong_Kong
as the sub-timezone of ‘Asia/’. You can input ‘?’ to list the timezones to choose from.
Check the Date
|
|
Make a dynamic MOTD
MOTD stands for “Message of the Day” in Linux. It is a customizable message that is displayed to users when they log in to the system.
Create a crond script
to dynamic create an motd
message to users
|
|
Command | Description |
---|---|
rc-service crond start | Starts the crond service, which runs scheduled tasks on the system. |
rc-update add crond | Adds the crond service to the default runlevel, ensuring that it starts automatically on boot. |
vi /etc/periodic/15min/motd | Use the Vi text editor and creates a new shell script at /etc/periodic/15min/motd . This script is executed every 15 minutes to update the MOTD. |
chmod a+x /etc/periodic/15min/motd | Sets the execute permission for the motd script, allowing the system to run it as a periodic task. |
run-parts --test /etc/periodic/15min | Tests the /etc/periodic/15min directory for executable scripts and prints a list of the scripts that would be executed by the system’s periodic task scheduler. |
Contents of /etc/periodic/15min/motd
|
|
This is the result:
Changing To The Bash Shell
Bash is a popular command shell in the Linux community, and many users prefer it over the default shell in Alpine Linux, which is ash. Changing to the Bash shell in Alpine Linux is a simple process that can greatly enhance our productivity and efficiency when working with the Linux system.
Alpine Linux uses Ash by default as the shell, but I prefer to use Bash as my Linux shell. To install Bash in Alpine Linux and make it the default shell, follow these steps:
Install Bash:
|
|
Change the default shell for your user:
|
|
Verify the change by checking the first line of the /etc/passwd
file:
|
|
It should display /bin/bash
.
Customize the Bash shell. We can configure the Bash shell liking by adding your aliases and settings. Here is an example of customization:
|
|
This customizes the Bash shell with aliases for common commands, a colored prompt, and auto-completion using the bash_completion.sh
script.
NeoVim and Vim plugins Install in Alpine Linux
NeoVim is a popular text editor that is designed to be more extensible and customizable than traditional editors like Vim. It offers many features that make it an excellent choice for developers and testers.
To install NeoVim and Vim plugins in Alpine Linux, follow these steps:
Install NeoVim using the apk package manager:
|
|
Install Vim plugins using the Vim plugin manager, such as Vim-Plug. First, download and install Vim-Plug:
|
|
Create the NeoVim configuration file:
|
|
Add the following lines to your init.vim file to set up Vim-Plug and install plugins:
|
|
Save and exit the init.vim file.
Open NeoVim:
|
|
Install the Vim plugins using the following command:
|
|
This will download and install the plugins specified in your init.vim file.
Setting up a new user
Installing sudo and assigning sudo privileges to a new user in Alpine Linux can greatly enhance your system’s security and flexibility.
Install sudo using the apk package manager:
|
|
(1/1) Installing sudo (1.9.12_p2-r1) Executing busybox-1.35.0-r29.trigger
Create a new user:
|
|
‘user’ as your UserName
|
|
Changing password for user New password: Bad password: too weak Retype password: passwd: password for user changed by root
also the new user using a bash shell as default shell and
Add the new user to the sudo group:
|
|
create a username file in the sudoers folder to allow the new user to use sudo:
Once you have completed these steps, the new user can use the sudo command to elevate their privileges when necessary. To use the sudo command, the user should prefix the command they want to run with “sudo”, like this:
|
|
For example, if the new user wants to install a new package using apk, they can use the following command:
|
|
This will prompt the user to enter their password before allowing the command to run with elevated privileges.
SSH key authentication to login
Update the package and Install OpenSSH:
|
|
/etc/init.d/sshd start
|
|
rc-update add sshd
|
|
Copy the public key to the remote server (Alpine Linux) using the ssh-copy-id command:
|
|
Enter your user password when prompted.
SSH into the remote server:
|
|
You should now be able to log in to the remote server without being prompted for your password.
Remote server setting (as server)
Disabling Password Authentication on your Server
|
|
|
|
|
|
- Caching service dependencies … [ ok ]
- Stopping sshd … [ ok ]
- Starting sshd … [ ok ]
Enable unprivileged users to use ICMP (Ping)
To fix the error “unprivileged ping is disabled, please enable by setting net.ipv4.ping_group_range” when trying to use the ping command, it means that non-root users are not allowed to use the ping command.
Add a new config file:
|
|
Apply the changes:
|
|
Execute all steps with a shell script.
|
|
Compatible only with Alpine Linux.
Conclusion
Alpine Linux is a highly customizable distribution of Linux that offers a wide range of customizations to enhance your experience with the system. By following the customizations outlined in this post, We can tailor Alpine Linux to our specific needs and preferences, making it a powerful and flexible tool for development and system administration.
Reference
- Alpine Linux Installation
- How to install bash shell in Alpine Linux
- Setting up a new user
- How To Configure SSH Key-Based Authentication on a Linux Server