Discover DevOps roles and learn Linux from basics to advanced at DevOpsRoles.com. Detailed guides and in-depth articles to master Linux for DevOps careers.
In this tutorial, I will configure the SSH connection with key authentication.
How it works
(Client) Generate a set of secret key and public key
(Connection destination server) Register public key
(Connection destination server) Accepts a connection from a client, encrypts the random number using the public key
(Connection destination server) Hashed random number
(Client) hashes the received random number and forwards the hash value to the server
(Connection destination server) Compare the hash value sent by the client and the hash value generated on the server side
Set up SSH connection with key authentication.
1: Generation of a key set
ssh-keygen -t rsa -f client01
2: Public Key Registration
# Work on the server, target users to connect
cat client01.pub >> .ssh/authorized_keys
3: Enabling Key Authentication
# vim /etc/ssh/sshd_config
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeyFile .ssh/authorized_keys
# Disable password authentication if you want to strengthen it
PasswordAuthentication no
Try to connect
ssh -i .ssh/client01 -p12345 huupv@devopsroles
Conclusion
Thought the article, How to configure SSH connection with key authentication in Linux. Thank you for reading the DevopsRoles page!
Only the command can be used for starting and stopping.
systemd service unit file
It is arranged under “/etc/systemd/system” with “unitname.service”
Others include directories like “/usr/lib/systemd” and “/lib/systemd“, but rather for systems.
Service section
Describe the operation parameters of the unit.
Type
The relationship between the execution command and the main process is represented by Type.
simple: ExecStart command remains as it is process
forking: Child process of ExecStart is process
: Even if ExecStart ends, the main process will remain.
Restart
Restart conditions can be specified with parameters equivalent to respawn in the old inittab.
always: always rerun
on-abort: re-execute when terminating with a signal that can not be caught
on-watchdog: Rerun with monitor timeout
on-abnormal: Re-execution when terminating with a signal other than SIGHUP, SIGINT, SIGTERM or SIGPIPE
on-failure: re-execution when the main process ends with a code other than the normal termination code
on-success: Rerun when the main process ends with a normal exit code
Install section
Specify which target (old ) should be executed when th is activated (enable).
For example, when enabling in multi-user mode (old run level 3), a symbolic link to a unit file is established under “/etc//system/multi-user.target“.
[Unit]
Description=Description
After=Execute after starting the specified unit list
Before=Execute before the specified unit list
Requires=Execute after the specified unit list has been successfully started
Wants=Even if the specified unit list fails to start up
[Service]
Environment=environment variable list
EnvironmentFile=environment variable file
Type=simple|forking|oneshot
ExecStart=start command
ExecStop=stop command
ExecReload=reload command
Restart=On-abort|on-watchdog|on-abnormal|on-failure|on-success|no
RemainAfterExit=yes|no
PIDFile=PID file path of main process
User=ExecXX execution user
SuccessExitStatus=(other than 0) EXIT code list to be regarded as a normal completion of the main process
[Install]
Alias=service alias list
WantedBy=target list
Also=unit list installed together
used commands
Unit file installation (loading)
$ sudo systemctl daemon-reload
Enable/disable
$ systemctl enable|disable unitname
Dependency display
$ systemctl list-dependencies unitname
For example, List Dependency of chronyd package.
Confirm startup sequence
Summary of time spent on startup (kernel, initrd, user)
$ systemd-analyze time
Time is taken to activate unit (currently active unit)
When the directory size displayed by the du command does not match between the parent directory and child directory in Linux. How to solve the problem? The parent directory is “and the child hidden directory is “.delete”
du command does not match directory size displayed
Folder devopsroles with 12M size as below
[huupv@server01 ~]$ du -sh devopsroles
12M devopsroles
Contain files and folders in devopsroles as below
[huupv@server01 devopsroles]$ ls -la
total 16
drwxr-xr-x 3 huupv huupv 4096 Feb 13 16:29 .
drwxr-xr-x 16 huupv huupv 4096 Feb 13 16:29 ..
drwxr-xr-x 2 huupv huupv 4096 Feb 13 16:07 .delete
-rw-r--r-- 1 huupv huupv 17 Feb 13 16:29 note.txt
-rw-r--r-- 1 huupv huupv 0 Feb 13 16:29 tmp.txt
In folder devopsroles different size with du -sh command.
[huupv@server01 ~]$ cd devopsroles/
[huupv@server01 devopsroles]$ pwd
/home/huupv/devopsroles
[huupv@server01 devopsroles]$ du -sh ./* | sort -hr
4.0K ./note.txt
0 ./tmp.txt
12M=4.0K + 0? Why does not it match?
Cause:du command does not show hidden directory size.
If you do the following, the file size including the hidden directory is displayed as the command below.
In this tutorial, you can solve the problem “directory size displayed by du does not match between the parent directory and child directory” in Linux. Thank you for reading the DevopsRoles page!
Linux offers various command-line tools that simplify system management, one of which is the date command in Linux. This command is crucial for both system administrators and regular users as it displays or sets the system’s date and time.
date command syntax
date [OPTION]… [+FORMAT] date [-u|–utc|–universal] [MMDDhhmm[[CC]YY][.ss]]
In the manual page, it describes the command as follows: date – prints or sets the system’s date and time. For more detailed information about the date command, refer to the manual page by entering man date in the terminal.
date command in Linux with Examples
$ date
Get year-month-day
[huupv@huupv devopsroles]$ date +%Y-%m-%d
2019-03-10
Get date command usage in Linux
[huupv@huupv devopsroles]$ date -d now
Sun Mar 10 13:18:55 +07 2019
[huupv@huupv devopsroles]$ date -d tomorrow
Mon Mar 11 13:19:00 +07 2019
[huupv@huupv devopsroles]$ date -d yesterday
Sat Mar 9 13:19:06 +07 2019
[huupv@huupv devopsroles]$ date -d last-sunday
Sun Mar 3 00:00:00 +07 2019
[huupv@huupv devopsroles]$ date +'%Y-%m-%d'
2019-03-10
Customizing the Output
One of the powerful features of the date command is its ability to format the output. You can customize how the date and time are displayed using format specifiers. For example, to display the date in YYYY-MM-DD format, you would use:
date +%Y-%m-%d
Conclusion
The date command in Linux is a straightforward yet widely used tool in Linux. It allows users to either display or set the system’s date and time from the terminal. Thank you for visiting the DevopsRoles page!
reboot command means Restart your machine gently. How do I reboot my Linux based system or remote Linux Server?
Syntax
reboot [OPTION]…
On the man page, the describes it
reboot – reboot or stop the system.
man reboot – More details information about reboot command.
reboot command in Linux with Examples
$ sudo reboot
reboot command within the last six minutes of TIME
$ sudo shutdown -r +6
How to identify the location reboot command in Linux.
[vagrant@localhost ~]$ which reboot
/usr/sbin/reboot
I will reboot the remote Linux Server with the following command as the below
$ ssh root@remote[IP]-server/usr/sbin/reboot
Conclusion
reboot command is the simple command in Linux. It is the most popular in use terminal Linux reboot or stops the system. Thank you for reading the DevopsRoles page!
shutdown command means Halt, power-off or reboots the machine. In this tutorial, How to shutdown command in Linux with Examples.
Syntax
shutdown [OPTION]… TIME [MESSAGE]
On the man page, describe it
shutdown – bring the system down.
man shutdown – More details information about the shutdown command.
The shutdown command in Linux with Examples
$ sudo shutdown -h now
#Schedule the system to shut down at 8 A.M.
$ sudo shutdown 8:00
#Schedule the system to shut down in fifteen minutes.
$ sudo shutdown +15 "Upgrading hardware, downtime should be minimal"
#Bring down the system immediately, and automatically reboot it.
$ sudo shutdown -r now
# Bring down the system immediately, and automatically power off the system.
$ sudo shutdown -P now
Related commands
halt – Stop the computer. poweroff – Stop the computer. reboot – Stop the computer. wall – Send a message to all logged-in users.
Conclusion
command is a simple command in Linux. It is the most popular in use terminal Linux to bring the system down. Thank you for reading the DevopsRoles page!
gunzip command in Linux, compressing and decompressing files are essential skills for users. One of the most popular commands for decompressing files in Linux is gunzip. This command helps decompress files that have been compressed using gzip, a common compression format in Unix-like systems. In this article, we will delve into the details of the gunzip command, how to use it, and provide practical examples that you can apply in your daily tasks.
Syntax
gunzip [ -acfhlLnNrtvV ] [-S suffix] [ name … ]
According to the man page, the gunzip command is used to compress or expand files.
To get more detailed information about the gunzip command, you can use:
man gunzip
gunzip command in Linux with Examples
$ gunzip devopsroles.txt.gz
Keep both the compressed and Decompressed files.
$ gunzip -k devopsroles.txt.gz
Display compressed within it without decompressing first.
$ gunzip -c devopsroles.txt.gz
Test Whether a Compressed File Is Valid before Decompressing it.
$ gunzip -t devopsroles.txt.gz
Show verbose information when you decompress the file.
$ gunzip -v devopsroles.txt.gz
Decompress Multiple Files at Once
gunzip file1.gz file2.gz file3.gz
To decompress a file while keeping the original compressed file, use the -c option and redirect the output:
gunzip -c file.gz > file
Conclusion
The gunzip command is a powerful and easy-to-use tool in Linux for decompressing gzip files. By mastering its options and syntax, you can save time and effort in file management. Hopefully, this article has provided you with a clearer understanding of how to use gunzip command in Linux effectively in your daily tasks. Keep exploring and leveraging the powerful tools of Linux to enhance your work efficiency and system management. Thank you for reading the DevopsRoles page!
unzip command in Linux means list, test, and extract compressed files in a ZIP archive. In the Linux operating system, compressing and decompressing files are essential skills for users. One of the most popular commands for decompressing ZIP files is unzip. This command not only helps to extract ZIP files but also provides many useful options for effective file management. In this article, we will explore the unzip command in detail, how to use it, and provide practical examples that you can apply in your daily tasks.
The unzip command is a powerful and flexible tool in Linux for extracting ZIP files. By mastering its options and syntax, you can improve your work efficiency and manage files more effectively. Hopefully, this article has given you a clearer understanding of how to use the unzip command and how to apply it to your daily tasks. Keep exploring and leveraging the powerful tools of Linux to enhance your work efficiency and system management. Thank you for reading the DevopsRoles page!
zip command is a simple command in Linux. It is the most popular in use terminal Linux package and compress (archive) files. Thank you for reading the DevopsRoles page!