Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why shouldn't I use timedatectl to set the timezone

Tags:

centos7

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?

like image 397
R.Lee Avatar asked Jul 29 '16 09:07

R.Lee


People also ask

What does Timedatectl set NTP do?

NTP stands for Network Time Protocol is an internet protocol, which is used to synchronize the system clock between computers. The timedatectl utility enables you to automatically sync your Linux system clock with a remote group of servers using NTP.

What does Timedatectl command do in Linux?

The timedatectl command allows you to both query and change the system clock and its settings on Linux systems. To display the current settings, use the command by itself—with no arguments.

How do I exit Timedatectl?

If timesync-status is invoked and this option is passed, then timedatectl monitors the status of systemd-timesyncd. service(8) and updates the outputs. Use Ctrl+C to terminate the monitoring.


3 Answers

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.

like image 72
Kevin Keane Avatar answered Oct 04 '22 08:10

Kevin Keane


I find that my /etc/localtime is not a symbolic links pointing to /usr/share/zoneinfo/... .

so I changed that file like this ,it works:

lrwxrwxrwx. /etc/localtime ->../usr/share/zoneinfo/Asia/Shanghai
like image 28
R.Lee Avatar answered Oct 04 '22 10:10

R.Lee


I used this commands to change timezone for my vicidial server with cent os 7 :

rm /etc/localtime

rm: remove regular file `/etc/localtime'

ln -s /usr/share/zoneinfo/Europe/Rome localtime

date and you will see that it is changed.

like image 29
Sotmir Laci Avatar answered Oct 04 '22 09:10

Sotmir Laci