Featured image of post How to Enable NTP in Debian 12

How to Enable NTP in Debian 12

Install system-timesyncd

  1. Uninstall ntpd
1
sudo apt purget ntp
  1. Install timesyncd
1
sudo apt install -y systemd-timesyncd
  1. Start timesyncd service
1
sudo systemctl start systemd-timesyncd
  1. enable service auto started
1
sudo systemctl enable systemd-timesyncd
  1. Check the status:
1
sudo systemctl status system-timesyncd
  1. Disply the current time and date.
1
timedatectl

Fix can’t start on wsl

  1. Modify config
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
#sudo sed -i '/ConditionVirtualization/c\ConditionVirtualization=' /etc/systemd/system/sysinit.target.wants/systemd-timesyncd.service
# Fix time sync issues in WSL
# https://github.com/microsoft/WSL/issues/8204#issuecomment-1338334154
sudo mkdir -p /etc/systemd/system/systemd-timesyncd.service.d
sudo tee /etc/systemd/system/systemd-timesyncd.service.d/override.conf > /dev/null <<'EOF'
[Unit]
ConditionVirtualization=
EOF
sudo systemctl start systemd-timesyncd
sudo systemctl enable systemd-timesyncd
  1. Reboot service
1
2
sudo systemctl daemon-reload   
sudo systemctl restart systemd-timesyncd
  1. Check systemd-timesyncd service status
1
sudo systemctl status systemd-timesyncd

with script

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
systemd_timesyncd_exist=$(sudo systemctl is-active systemd-timesyncd | grep active | wc -l)
echo $systemd_timesyncd_exist
if [ $systemd_timesyncd_exist -ne 1 ]
then
    sudo apt update -y
    sudo apt purget ntp -y
    sudo apt install -y systemd-timesyncd
    sudo systemctl start systemd-timesyncd
    sudo systemctl enable systemd-timesyncd
fi
sudo mkdir -p /etc/systemd/system/systemd-timesyncd.service.d
echo 'hello'
sudo tee /etc/systemd/system/systemd-timesyncd.service.d/override.conf > /dev/null <<'EOF'
[Unit]
ConditionVirtualization=
EOF

sudo systemctl daemon-reload   
sudo systemctl restart systemd-timesyncd
Built with Hugo
Theme Stack designed by Jimmy