Tuesday, August 30, 2022

[SOLVED] Why shouldn't I use timedatectl to set the timezone

Issue

When I use timedatectl to set the timezone, it happens

[root@localhost ~]# timedatectl set-timezone "America/New_York"
Failed to set time zone: Access denied

This's my host infomation

Static hostname: rolin
Icon name: computer-vm
Chassis: vm
Machine ID: 699591c5339c2ae6d7e7b25151eaa987
Boot ID: 40dc52c07c85444c9514f7d92a24448e
Virtualization: kvm
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-327.18.2.el7.x86_64
Architecture: x86-64

What can I do now?


Solution

The root cause of this problem is probably an SELinux labeling issue. The fix is to relabel the /etc directory:

restorecon -Rv /etc

Then re-run the timedatectl command.

Source: https://access.redhat.com/solutions/3366211 (link requires a RedHat login).

Or if you can't do that for some reason, as a workaround you could temporarily set SELinux to permissive mode, update the time zone, and then re-enable SELinux.

However, that second approach will not fix the underlying problem. A mis-labeling in /etc may well cause other problems down the road.



Answered By - Kevin Keane
Answer Checked By - Marilyn (WPSolving Volunteer)