Category Archives: LINUX

How to change date, time, timezone on centos 6

Display Date and Time in Linux

and its output

Change Timezone in Linux

Fist, we are going to get a list of timezone that came with Linux.

There are countries, or continent with different timezone, for example when you list all file and directories in zoneinfo directory as I did above, there are timezone for countries with only one timezone, and directories for countries and continent with several timezones. For example my timezone is America Pacific, I will need to go to America directory to get my timezone.

I will use Toronto for Pacific time, so I will need to copy/set Toronto file as my localtime on my server (this will work with any linux system I believe).

Change Date and Time in Linux

Now your Linux system should have the timezone that you want. If the date or time is not correct, you can set date and time with date command.

  • MM: two digit month number
  • DD: two digit date
  • hh: two digit hour (24 hour system)
  • mm: two digit minute
  • YYYY: four digit of year

You can also sync your system time and date with ntp (Network Time Protocol) over a network or internet. Normally ntp should be installed to your Linux system as default, in case your system does not have ntp, you can easily install ntp package with a simple command.

To install ntp on Ubuntu, Linux or debian based distribitions

To install ntp on Fedora, Centos or redhat based distribitions

After you set your timezone correcly, you should be able to synce your date and time with ntp command

Note: if you have a VPS (virtual private server) and not a real dedicated server, you will properly won’t be able to adjust time on your VPS. When you are on VPS, you do not have the right to modify or update time and date, only the VPS owner or provider have the rights to adjust time and date on that VPS node.

Recover the SUSE Linux root password

  1. Boot server from the installation CD.
  2. Then select “Rescue System”
  3. Login as root
  4. Type
    fdisk -l

    to list the partitions. Locate the Linux root partition

CASE 1 – root partition is not LVM filesystem

mount /dev/sda2 /mnt
(replace sda2 with the device name for the Linux root partition identified in your system).

mount –bind /dev /mnt/dev
to make the device files available (this is needed for access to the urandom device which may be used by thepasswd command below).

chroot /mnt /bin/bash
passwd root

and reset the root password.

CASE 2 – root partition is LVM filesystem

# lvm vgscan -v

Activate all volume groups:
# lvm vgchange -a y

List logical volumes:
# lvm lvs –all

With this information, and the volumes activated, you should be able to mount the volumes:
# mount /dev/mapper/yourfilesystem  /mnt

mount –bind /dev /mnt/dev
to make the device files available (this is needed for access to the urandom device which may be used by thepasswd command below).

chroot /mnt /bin/bash
passwd root

and reset the root password.