Setting the Date and Time


Setting the date and time is very important for a system administrator. Why? Because if you find something inappropriate or possibly problematic in your log files (e.g., repeated unsuccessful login attempts from a specific location), you want to be able to accurately cross-reference your log files with the log files of your colleagues at the other location. That can happen only if the time on both hosts is pretty close to accurate.

To Set the Time with ntpdate:

  • sudo /usr/sbin/ntpdate 192.168.96.3

    Use ntpdate with the name of a time server (currently available servers are listed at www.ntp.org) to update your system clock to the current, accurate time (Code Listing 16.7). If you get an error message about the socket being in use, use ps ef | grep ntp to find the ntp daemon that's running to keep your time synchronized. (If this happens, your time is probably OK and doesn't need to be set.)

    Or

  • sudo date -s "Tues Jan 27 5:30:23 2003

    If your system doesn't have ntpdate, you'll have to set the time manually. Use sudo, date, and all the rest of the needed information. (If you need to change, say, only the time, you can just provide the time, as in sudo date s 5:45).

Tip

  • It's much better to use ntpdate or have the nptd daemon run to keep your time up-to-date at all times. Using date manually is a poor second choice.


Code Listing 16.7. Setting the date (and making sure it stays up-to-date) is an important root user responsibility.

[jdoe@frazz jdoe]$ sudo /usr/sbin/ntpdate  192.168.96.3 27 Jan 05:26:50 ntpdate[1470]: adjust time  server 192.168.96.3 offset -0.004140 sec [jdoe@frazz jdoe]$ sudo date -s 5:30 Mon Jan 27 05:30:00 MST 2003 [jdoe@frazz jdoe]$ sudo date -s "Tues  Jan 28 5:30:21 Tue Jan 28 05:30:21 MST 2003 [jdoe@frazz jdoe]$ sudo date -s "Tues  Jan 28 5:30:21 2004 Password: Wed Jan 28 05:30:21 MST 2004 [jdoe@frazz jdoe]$ sudo date -s "Mon Jan  27 5:30:21 2003 Mon Jan 27 05:30:21 MST 2003 [jdoe@frazz jdoe]$ date Mon Jan 27 05:30:35 MST 2003 [jdoe@frazz jdoe]$ sudo /usr/sbin/  ntpdate 192.168.96.3 27 Jan 05:30:38 ntpdate[1616]: step time server 192.168.96.3 offset -7.329083 sec [jdoe@frazz jdoe]$ sudo /usr/sbin/  ntpdate 192.168.96.3 27 Jan 05:30:44 ntpdate[1622]:adjust time server 192.168.96.3 offset 0.000479 sec [jdoe@frazz jdoe]$ 




Unix(c) Visual Quickstart Guide
UNIX, Third Edition
ISBN: 0321442458
EAN: 2147483647
Year: 2006
Pages: 251

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net