RED HAT ENTERPRISE LINUX
Configure autofs
Configure autofs
CIS126RH | RHEL System Administration 1
Mesa Community College
autofs — the automounter — mounts filesystems on demand the moment they
are accessed and unmounts them automatically after a configurable idle timeout. This
eliminates the need to keep NFS shares permanently mounted when they may only be needed
occasionally, prevents boot failures when NFS servers are temporarily unavailable, and
scales to large environments where hundreds of home directories would be impractical
to list in /etc/fstab. autofs configuration is a distinct RHCSA exam
objective and is tested with specific scenario tasks.
Learning Objectives
- Explain how autofs works — Describe the autofs on-demand mounting model, the role of the kernel automounter, and why autofs is preferred over fstab for certain use cases
-
Install and configure the autofs service —
Install the
autofspackage, understand the master map and map file structure, and enable the service - Configure indirect maps — Write master map and indirect map file entries to automount NFS shares as subdirectories of a base directory
-
Configure the wildcard home directory pattern —
Use the
*and&substitution in a map file to automount any user's home directory on demand
How autofs Works
autofs intercepts filesystem access at directories it manages and mounts the target on demand — the user never sees a difference from a permanently mounted filesystem, except that the mount only exists while in use.
- autofs registers itself with the kernel as a filesystem handler for configured directories
- When a process accesses
/shares/data, the kernel asks autofs to handle it - autofs looks up
datain its map file, finds the NFS target, and mounts it - The process sees the mounted directory contents — no mount command required
- After a configurable idle timeout (default 300 seconds), autofs unmounts the share
- If the NFS server is unavailable, autofs returns "No such file or directory" rather than hanging
Use /etc/fstab when a share must always be mounted and the server is
reliable. Use autofs when: mounts are needed only occasionally, the
server may be temporarily unavailable, or many mounts (e.g. user home directories)
would make fstab unmanageable.
Installing autofs
The autofs package provides the daemon, configuration files, and
systemd service unit.
# Install the autofs package
$ sudo dnf install -y autofs
# NFS support also requires nfs-utils
$ sudo dnf install -y nfs-utils
# Enable and start the autofs service
$ sudo systemctl enable --now autofs
# Confirm autofs is running
$ systemctl status autofs
● autofs.service - Automounts filesystems on demand
Loaded: loaded (/usr/lib/systemd/system/autofs.service; enabled)
Active: active (running) since ...
# View the autofs configuration files installed
$ rpm -ql autofs | grep etc
/etc/auto.master
/etc/auto.misc
/etc/auto.net
/etc/auto.smb
/etc/autofs.conf
/etc/autofs_ldap_auth.conf
After editing map files, use sudo systemctl reload autofs —
reload re-reads all map files without interrupting existing mounts.
Use restart only if the daemon itself needs to be restarted.
The autofs Configuration Model
autofs uses two levels of configuration: the master map defines which directories autofs manages; map files define what gets mounted at each key within those directories.
# /etc/auto.master — the master map
# Format: BASE_DIR MAP_FILE [OPTIONS]
/misc /etc/auto.misc
/mnt /etc/auto.mnt --timeout=60
/home /etc/auto.home --timeout=300
/- /etc/auto.direct
# A map file — /etc/auto.mnt
# Format: KEY [-OPTIONS] LOCATION
data -rw,sync,hard servera:/exports/data
logs -ro servera:/exports/logs
backup -rw 192.168.1.20:/backup
| Master map field | Meaning |
|---|---|
| Base directory | The directory autofs manages (must exist or autofs creates it) |
| Map file | Path to the file listing individual mounts under the base directory |
--timeout=N | Seconds of inactivity before auto-unmounting (default 300) |
The Master Map: /etc/auto.master
The master map is the starting point for all autofs configuration. Every autofs-managed directory is registered here.
# View the default /etc/auto.master on RHEL 9
$ cat /etc/auto.master
#
# This is the master map file for autofs.
# See auto.master(5) for details.
#
+dir:/etc/auto.master.d
+auto.master
/misc /etc/auto.misc
/net -hosts
# Add a new section to manage /shares with map file /etc/auto.shares
/shares /etc/auto.shares --timeout=300
# Alternative: use the drop-in directory (survives package updates)
$ sudo tee /etc/auto.master.d/shares.autofs <<'EOF'
/shares /etc/auto.shares --timeout=300
EOF
# Reload autofs to apply the new master map entry
$ sudo systemctl reload autofs
Files ending in .autofs in /etc/auto.master.d/ are
automatically included in the master map. This is the preferred location for
site-specific entries — they survive autofs package updates that
might reset /etc/auto.master.
Indirect Map Configuration
An indirect map defines a base directory managed by autofs. Each key in the map file becomes a subdirectory that triggers an automatic mount.
# Step 1: Create the base directory
$ sudo mkdir -p /shares
# Step 2: Add to /etc/auto.master (or drop-in)
$ sudo vim /etc/auto.master
# Append this line:
/shares /etc/auto.shares --timeout=300
# Step 3: Create the map file /etc/auto.shares
$ sudo vim /etc/auto.shares
# Format: KEY [-OPTIONS] SERVER:/EXPORT
data -rw,sync,hard,intr servera:/exports/data
logs -ro servera:/exports/logs
# Step 4: Reload autofs
$ sudo systemctl reload autofs
# Step 5: Test — accessing /shares/data triggers the mount
$ ls /shares/data
$ mount | grep shares
servera:/exports/data on /shares/data type nfs4 (rw,...)
mkdir base → edit auto.master → create map file → reload autofs → test with ls.
The ls triggers the mount; do not use mount manually.
Map File Format in Detail
Each line in a map file has three parts. Options are optional but the dash prefix is required when options are specified.
# Map file format:
# KEY [-OPTIONS] LOCATION
# Example entries
data -rw,sync,hard servera:/exports/data
logs -ro servera:/exports/logs
usb -fstype=vfat,uid=1000 :/dev/sdb1
iso -fstype=iso9660,ro :/dev/cdrom
* -rw,sync,hard servera:/home/&
| Field | Description | Example |
|---|---|---|
| KEY | The subdirectory name that triggers the mount. * matches any key. | data, * |
| OPTIONS | Mount options prefixed with a dash. Comma-separated. Optional. | -rw,sync,hard |
| LOCATION | NFS: SERVER:/path. Local: :/dev/device. With & for wildcard substitution. | servera:/exports/data |
Options in map files must be prefixed with a dash: -rw,sync.
Without the dash, autofs cannot parse the line and silently ignores it —
the mount will not work but no error is reported in the standard output.
Direct Map Configuration
A direct map mounts NFS shares at explicit absolute paths anywhere in the filesystem tree — not as subdirectories of a base directory.
# /etc/auto.master — direct map uses /- as the base directory
/- /etc/auto.direct
# /etc/auto.direct — absolute paths as keys
# Format: ABSOLUTE_PATH [-OPTIONS] LOCATION
/data -rw,sync servera:/exports/data
/var/reports -ro servera:/exports/reports
/opt/apps -ro servera:/exports/apps
# The directories must exist before autofs can manage them
$ sudo mkdir -p /data /var/reports /opt/apps
$ sudo systemctl reload autofs
# Test
$ ls /data # triggers mount of servera:/exports/data at /data
Indirect: multiple mounts under a common parent directory —
e.g. /shares/data, /shares/logs.
Direct: mounts at specific arbitrary paths —
e.g. /data, /var/reports.
Wildcard Home Directory Automounting
The most important autofs exam pattern: mount any user's home directory
on demand using a single map file entry with the * wildcard
and & substitution.
# Scenario: NFS server exports /home/USERNAME for each user
# Goal: /home/student1 automounts as servera:/home/student1 on demand
# Step 1: Add to /etc/auto.master
/home /etc/auto.home --timeout=300
# Step 2: Create /etc/auto.home
$ sudo vim /etc/auto.home
# * = matches any username; & = substitutes matched value
* -rw,sync,hard servera:/home/&
# Step 3: Reload autofs
$ sudo systemctl reload autofs
# Step 4: Test — access a user's home directory
$ ls /home/student1 # mounts servera:/home/student1
$ ls /home/operator1 # mounts servera:/home/operator1
$ mount | grep home
servera:/home/student1 on /home/student1 type nfs4 (rw,...)
The * and & Substitution
Understanding exactly how * and & interact
is essential for writing correct wildcard map entries.
# Map file entry
* -rw,sync servera:/home/&
# When /home/alice is accessed:
# * matches "alice"
# & substitutes to "alice"
# autofs mounts: servera:/home/alice → /home/alice
# When /home/ldapuser3 is accessed:
# * matches "ldapuser3"
# & substitutes to "ldapuser3"
# autofs mounts: servera:/home/ldapuser3 → /home/ldapuser3
# The & can appear anywhere in the location path:
* -ro servera:/exports/users/&/data
# /home/alice → servera:/exports/users/alice/data
# Without & — every key mounts the SAME path (unusual)
* -ro servera:/exports/shared
# /home/ANYUSER → servera:/exports/shared (same for everyone)
* is the pattern that matches any key value in the map.
& is the substitution that inserts the matched value into
the server path. Both are needed together for per-user home directories.
autofs Timeout and Global Configuration
The autofs daemon reads its global settings from /etc/autofs.conf.
Per-map timeouts are set in the master map.
# View/edit the global autofs configuration
$ cat /etc/autofs.conf
[autofs]
timeout = 300 # default idle timeout in seconds
negative_timeout = 60 # how long to cache a failed lookup
browse_mode = no # show managed dirs even when not mounted
logging = none # logging level: none, verbose, debug
# Set per-map timeout in the master map (overrides global)
/home /etc/auto.home --timeout=600 # 10 minutes for home dirs
/shares /etc/auto.shares --timeout=60 # 1 minute for shared data
# Check how long a mount has been idle
$ automount --pid-file /run/autofs.pid -f
# View autofs debug output
$ sudo journalctl -u autofs -f
Setting browse_mode = yes in /etc/autofs.conf
makes autofs-managed directories visible in directory listings even before
they are accessed. Useful when users need to see available shares without
clicking through to access them.
Verifying autofs Operation
Confirming that autofs is correctly configured requires checking the service, triggering a mount, and reading the result.
# Confirm autofs service is running
$ systemctl status autofs
# List what autofs is currently managing
$ automount --version
# Trigger a mount by listing a managed directory
$ ls /shares/data
# Confirm the mount is active
$ mount | grep autofs
autofs on /shares type autofs (rw,relatime,fd=...)
servera:/exports/data on /shares/data type nfs4 (rw,...)
# Confirm with df -hT
$ df -hT /shares/data
Filesystem Type Size Used Avail Use% Mounted on
servera:/exports/data nfs4 10G 3.2G 6.8G 32% /shares/data
# Watch autofs log for mount/unmount events
$ sudo journalctl -u autofs --since "5 minutes ago"
Troubleshooting autofs
When autofs does not mount a share as expected, a systematic diagnosis finds the cause quickly.
# Check autofs service status and recent log entries
$ systemctl status autofs
$ sudo journalctl -u autofs --since "10 minutes ago"
# Verify the master map is correctly parsed
$ sudo automount --dumpmaps
map /etc/auto.master has 2 entries:
/shares /etc/auto.shares
/home /etc/auto.home
# Check if the NFS server is reachable
$ showmount -e servera
# Test the NFS mount manually to isolate autofs from NFS issues
$ sudo mount -t nfs servera:/exports/data /mnt/test
$ sudo umount /mnt/test
# Enable verbose autofs logging temporarily
$ sudo vim /etc/autofs.conf
# Change: logging = none to: logging = verbose
$ sudo systemctl restart autofs
| Symptom | Likely cause |
|---|---|
| Directory not visible under base path | autofs not running, or master map entry missing/typo |
| ls returns "No such file or directory" | Map file entry missing, NFS server unreachable, or options have no leading dash |
| Mount hangs indefinitely | NFS server reachable but not responding — check firewall and NFS service on server |
| Changes not taking effect | autofs not reloaded after config change |
autofs Quick Reference
| Task | Command or configuration |
|---|---|
| Install autofs | sudo dnf install -y autofs nfs-utils |
| Enable and start autofs | sudo systemctl enable --now autofs |
| Reload after config changes | sudo systemctl reload autofs |
| Master map file | /etc/auto.master |
| Master map drop-in directory | /etc/auto.master.d/*.autofs |
| Master map entry (indirect) | /BASE /etc/auto.MAPFILE --timeout=300 |
| Master map entry (direct) | /- /etc/auto.direct |
| Map file entry format | KEY -OPTIONS SERVER:/EXPORT |
| Wildcard home directory entry | * -rw,sync,hard SERVER:/home/& |
| Trigger a mount (access) | ls /BASE/KEY |
| Verify mount is active | mount | grep autofs or df -hT /BASE/KEY |
| Dump all autofs maps | sudo automount --dumpmaps |
| View autofs log | sudo journalctl -u autofs |
Common Mistakes
| Mistake | What goes wrong | Correct approach |
|---|---|---|
| Missing the leading dash before map file options | autofs cannot parse the line — mount silently fails with "No such file or directory" | KEY -rw,sync SERVER:/path — the dash before options is mandatory |
| Editing map files but not reloading autofs | Changes have no effect — autofs still uses the old in-memory configuration | sudo systemctl reload autofs after every map file change |
| Forgetting the & in the wildcard location | All keys mount the same server path instead of user-specific paths | * -rw SERVER:/home/& — & substitutes the matched key |
| Base directory does not exist before autofs reload | autofs fails to register the map — entries under the base path are inaccessible | Create the base directory first: sudo mkdir -p /BASE |
| Trying to manually mount within an autofs-managed directory | Manual mounts conflict with autofs management — unpredictable behaviour | Let autofs manage its directories — do not run mount manually inside them |
| Configuring autofs and fstab for the same mount point | Both try to manage the same path — boot errors or mount conflicts | Use either autofs or fstab for a given path, never both |
Knowledge Check
Answer these before moving to the next slide.
- What are the two configuration files needed to configure a new autofs indirect mount, and what does each one contain?
- Write the complete configuration (master map entry and map file entry) to
automount
fileserver:/exports/reportsat/reports/monthlywhen accessed, with read-only access. - Write the
/etc/auto.masterentry and the/etc/auto.homemap file entry to automount any user's home directory fromnfsserver:/home/USERNAMEat/home/USERNAME. - What does the
&symbol do in an autofs map file, and why is it needed in the wildcard home directory pattern? - You edit
/etc/auto.sharesto add a new NFS share. What command must you run for the change to take effect without interrupting existing mounts? - An autofs share fails to mount — the directory appears empty when accessed. Write two commands to begin diagnosing the problem.
Knowledge Check — Answers
- Two files: /etc/auto.master (the master map) contains the base directory, the path to the map file, and global options like timeout. /etc/auto.MAPFILE (the map file) contains individual entries with the key, mount options, and NFS server path.
- In
/etc/auto.master:/reports /etc/auto.reports --timeout=300
Create/etc/auto.reportswith:monthly -ro fileserver:/exports/reports
Create the base dir:sudo mkdir -p /reports, then reload autofs. - In
/etc/auto.master:/home /etc/auto.home --timeout=300
In/etc/auto.home:* -rw,sync,hard nfsserver:/home/& &(ampersand) substitutes the value matched by the*wildcard into the location field. Without it, every user would mount the same fixed server path. With it, accessing/home/alicebuilds the pathnfsserver:/home/aliceand accessing/home/bobbuildsnfsserver:/home/bob— each user gets their own home directory.sudo systemctl reload autofs— reload re-reads all map files immediately without stopping the daemon or interrupting any existing active mounts.- Any two of:
sudo journalctl -u autofs --since "10 minutes ago"(check service log),sudo automount --dumpmaps(verify the map entry is parsed),showmount -e SERVERNAME(verify the NFS export exists),systemctl status autofs(confirm the service is running).
Key Takeaways
-
autofs mounts on demand and unmounts automatically.
Install
autofsandnfs-utils. Enable withsystemctl enable --now autofs. Reload — not restart — after config changes:systemctl reload autofs. -
Two files configure every indirect mount: master map + map file.
Master map entry:
/BASE /etc/auto.MAPFILE --timeout=300. Map file entry:KEY -OPTIONS SERVER:/export. The base directory must exist. The leading dash on options is mandatory. -
The wildcard pattern handles all home directories with one entry.
Master map:
/home /etc/auto.home. Map file:* -rw,sync,hard SERVER:/home/&.*matches any username;&substitutes it into the path. -
Trigger mounts with
ls; verify withmount | grep autofs. Never runmountmanually inside autofs-managed directories. Useautomount --dumpmapsto confirm map files are parsed correctly. Checkjournalctl -u autofsfor errors.
Graded Lab
- Install
autofsandnfs-utils. Enable and start the autofs service. Confirm it is running withsystemctl status autofs. - Configure an indirect map: add
/shares /etc/auto.shares --timeout=60to/etc/auto.master. Create/etc/auto.shareswith one entry mounting an NFS export from your lab server at/shares/labdata. - Create the
/sharesbase directory, reload autofs, and test by runningls /shares/labdata. Confirm the mount withmount | grep sharesanddf -hT /shares/labdata. - Wait 60 seconds (the timeout set in step 2) and run
mount | grep sharesagain to confirm the share was automatically unmounted. Then access it again to confirm it remounts on demand. - Configure autofs to handle home directories: add
/home /etc/auto.hometo/etc/auto.master. Create/etc/auto.homewith the wildcard entry. Reload autofs and test by accessing a home directory that exists on the NFS server. - Run
sudo automount --dumpmapsto verify both map entries are parsed. Runsudo journalctl -u autofs --since todayto review mount and unmount events from the session.
"Configure autofs."
Know the two-file model (auto.master + map file), the leading dash for options,
the wildcard * and & pattern for home directories,
and systemctl reload autofs after every change.