Linux › Section G · System configuration › Topic G.4
getty, login, and setting the time
Two small jobs happen on every machine before anyone does real work: a text terminal turns into a login prompt, and the system clock is kept right. Both are simple once you see which program owns each step.
From terminal to shell: getty and login
On a text console, a program called a getty opens the terminal device, prints the contents of /etc/issue, asks for a login name and then runs /bin/login with that name. login asks for the password (checking it through PAM, covered later in this section), sets the user's UID, GID, groups and environment, shows /etc/motd, and finally starts the user's login shell. Most distributions use agetty. When the shell exits, the terminal returns to a fresh getty. Graphical logins use a display manager and remote logins use sshd instead, but they reach the same account database and PAM.
How systemd starts the getty
Under systemd, each terminal has its own service instance. getty@tty1.service runs a getty on virtual console 1, and further consoles are started on demand as you switch to them. Serial lines use serial-getty@ttyS0.service, which is how servers with a serial console let you log in. Run systemctl status getty@tty1 to see one. After a successful login, systemd-logind records a session, and loginctl list-sessions shows the active ones. To skip the prompt on a kiosk, agetty accepts --autologin USER, which gives that user a shell without a password, so use it only where physical access is controlled.
Customising what users see
/etc/issue is shown before the prompt. It may contain escape codes expanded at display time: \n is the hostname, \l the terminal line, \d the date, \t the time, \s the operating system name, \r the kernel release, and \4 or \6 an IPv4 or IPv6 address. /etc/motd, the message of the day, appears after a successful login. If a file named /etc/nologin exists, ordinary users are refused at login and shown the file's text, while root can still log in, which is a handy way to block logins during maintenance. Remember to delete it afterwards.
How the kernel keeps time
The kernel counts time as seconds since 00:00:00 UTC on 1 January 1970, the Unix epoch. The count is the same for everyone on Earth, and a time zone is only a rule for displaying it. Separately, a battery-backed hardware clock, the RTC, keeps time while the machine is off; at boot the kernel reads it, and hwclock can read or write it. The RTC should normally hold UTC. Windows traditionally stores local time in the RTC, which causes a wrong clock on dual-boot machines until one system is told otherwise: timedatectl set-local-rtc 0 selects UTC. date +%s prints the current epoch count, and date -u -d @N converts a count back to a date.
Worked example: converting epoch seconds
What moment is 1,800,000,000 seconds after the epoch? 1. Divide by 86,400 seconds per day: about 20,833 days and a remainder. 2. Run date -u -d @1800000000, which prints Fri Jan 15 08:00:00 UTC 2027 (the date is a Friday; the arithmetic is easy to confirm in python with datetime.fromtimestamp(1800000000, timezone.utc)). 3. Check the reverse: the earlier count 1,000,000,000 is 9 September 2001 at 01:46:40 UTC. 4. Note the limit for old 32-bit counters: 2,147,483,647 seconds is 19 January 2038 at 03:14:07 UTC, the point at which a signed 32-bit time_t overflows. Current 64-bit systems are not affected.
Time zones and timedatectl
The zone database lives under /usr/share/zoneinfo, and /etc/localtime is a symbolic link to one of its files. timedatectl is the tool to manage it. timedatectl status (the default) shows local time, UTC, RTC time, the time zone, whether the clock is synchronised and whether an NTP service is active. timedatectl list-timezones lists names such as Europe/London; timedatectl set-timezone America/New_York changes the link. This changes how time is shown, not the epoch count. A single command can use another zone through the TZ variable, for example TZ=Asia/Tokyo date, without touching the system setting.
Worked example: one meeting, four zones
A meeting is set for 14:00 in America/New_York on Friday 6 November 2026. 1. Daylight saving in the United States ended on Sunday 1 November 2026, so New York is on standard time, UTC-5. 2. Add five hours: 19:00 UTC, which is the epoch count 1793991600. 3. London is on UTC in November, so also 19:00. 4. Tokyo is UTC+9: 04:00 on Saturday 7 November. 5. Los Angeles is UTC-8: 11:00 on Friday. Check: 14:00 + 5 h = 19:00; 19:00 + 9 h = 28:00, which is 04:00 on the next day. Servers kept in UTC avoid this arithmetic entirely.
Keeping the clock right: NTP
A hardware clock drifts, so machines ask a network time source. Two common clients exist. systemd-timesyncd is a lightweight client that ships with many systemd distributions; timedatectl timesync-status reports its state. chrony (chronyd) is a fuller implementation, standard on Fedora and RHEL and widely used on servers; chronyc tracking shows the current offset and chronyc sources lists the servers. timedatectl set-ntp true enables and starts the first available synchronisation service. Large errors are corrected by stepping the clock, while small ones are corrected gradually so time never runs backwards in the middle of a job. If NTP is on, timedatectl set-time is refused; turn NTP off first.
Common mistakes to avoid
First, thinking a time-zone change alters the real clock; only the display changes. Second, leaving the RTC in local time on a Linux-only machine, which makes daylight-saving changes awkward. Third, setting the time by hand while NTP runs, then wondering why it snaps back. Fourth, forgetting that scheduled jobs, log timestamps and certificates all depend on the clock, so a wrong clock can break logins to remote services. Fifth, leaving /etc/nologin in place after maintenance. Sixth, using autologin on a machine that strangers can reach.
Key takeaways
agetty prints /etc/issue and asks for a name; login checks the password through PAM, sets up the environment and starts the shell. Under systemd each console is a getty@ttyN or serial-getty@ttyS0 service, and logind tracks sessions. /etc/nologin blocks ordinary users. The kernel counts seconds since 1970-01-01 00:00:00 UTC, the RTC should hold UTC, and /etc/localtime selects a display zone. timedatectl handles zone, status and NTP; chrony or timesyncd keep the clock accurate.
Flashcards
Flashcard
Opens a terminal, shows /etc/issue, asks for a login name
Test your understanding
Question 1 of 5
Which program prompts for a login name on a text console and then starts /bin/login?
Question 2 of 5
What does the Linux kernel's system clock count?
Question 3 of 5
A meeting is at 14:00 in New York (UTC-5) on 6 November 2026. What time is it in Tokyo (UTC+9)?
Question 4 of 5
Which command enables and starts network time synchronisation?
Question 5 of 5
What changes when you run timedatectl set-timezone Europe/London?
