The system time on a Linux machine is stored as the number of seconds since the Unix epoch (January 1, 1970, 00:00:00 UTC). You can display the current system time in a human-readable format using the date
command in the terminal. For example:
#date
Changing the system time can have unintended consequences, so be careful when doing so. It’s usually better to use a time synchronization service, such as ntp
or chrony
, to keep the system time accurate.
Synchronize the time in a Linux system using ntp
To synchronize the time in a Linux system, you can use the ntp
(Network Time Protocol) service.
You can install the ntp
package with the following command (for Ubuntu/Debian):
#sudo apt-get install ntp
And for Fedora/CentOS:
#sudo yum install ntp
After installation, you can start the ntp service and enable it to start at boot time:
sudo systemctl start ntp
sudo systemctl enable ntp
You can verify the time synchronization with the following command:
#ntpq -p
This will show the list of NTP servers that your system is synchronized with and their offset from the local clock.
Synchronize the time in a Linux system using chrony
chrony is another popular service for synchronizing the system clock on Linux. It is often used as an alternative to ntp due to its more efficient handling of time synchronization in dynamic network environments, such as those with changing IP addresses.
To install chrony on Ubuntu/Debian, you can use the following command:
#sudo apt-get install chrony
And for Fedora/CentOS:
#sudo yum install chrony
After installation, you can start the chrony service and enable it to start at boot time:
#sudo systemctl start chronyd #sudo systemctl enable chronyd
You can verify the time synchronization with the following command:
#chronyc tracking
This will show the state of the system clock and the sources that chrony is using to synchronize it.
Add Comment