Home Linux & Systems Cybersecurity Cloud & DevOps Networks & Infrastructure SIEM & Monitoring DFIR & Threat Intel Development & Other All categories Projects About Tools

Autofs and automount to serve cifs/smb

Leer en espanol
Autofs and automount to serve cifs/smb

Table of contents

automount and autofs are powerful tools that allow you to easily manage the file system. These programs allow all users to automatically mount different file systems on the same machine whenever necessary.

Installing Autofs

Redhat and derivatives:

Bash
[root@redorbita1 hare_data]# yum install autofs samba-client samba-common

Debian and derivatives:

Bash
[root@redorbita1 hare_data]#  apt-get install autofs samba-client

Next you have to add the following line in /etc/auto.master

Bash
[root@redorbita1 hare_data]# cat /etc/auto.master

# file: /etc/auto.master

# …

# …

/mnt/cifs_share /etc/auto.cifs –timeout=600 –ghost

Let's create the new file /etc/auto.cifs with the following content.

Bash
[root@redorbita1 hare_data]# cat /etc/auto.cifs

hare_data -fstype=cifs,rw,noperm,credentials=/etc/credentials.txt ://192.168.1.155/data

And finally we create the file with the credentials:

Bash
[root@redorbita1 hare_data]#cat /etc/credentials.txt

username=autofs

password=c0ntr4s3n4.

We grant the appropriate permissions to the files

Bash
[root@redorbita1 hare_data]# chmod -x /etc/auto.master /etc/auto.cifs

we restart the service

Bash
[root@redorbita1 hare_data]# service autofs restart

We access the folder

Bash
[root@redorbita1 hare_data]# cd /mnt/cifs_share/hare_data

[root@redorbita1 hare_data]# ls -lsrth

total 512

512 -rwxr-xr-x 1 root root 10 Jun 12 13:22 prueba.txt

We check in the log that everything is set up correctly:

Bash
[root@redorbita1 hare_data]# tail -f /var/log/messages

Jun 16 11:41:51 redorbita1 automount[937]: do_mount: //192.168.1.155/data /mnt/cifs_share/hare_data type cifs options rw,noperm,credentials=/etc/credentials.txt using module generic

Jun 16 11:41:51 redorbita1 automount[937]: mount_mount: mount(generic): calling mkdir_path /mnt/cifs_share/hare_data

Jun 16 11:41:51 redorbita1 automount[937]: mount_mount: mount(generic): calling mount -t cifs -s -o rw,noperm,credentials=/etc/credentials.txt //192.168.1.155/data /mnt/cifs_share/hare_data

Jun 16 11:41:51 redorbita1 automount[937]: spawn_mount: mtab link detected, passing -n to mount

Jun 16 11:41:51 redorbita1 kernel: Key type dns_resolver registered

Jun 16 11:41:51 redorbita1 kernel: Key type cifs.spnego registered

Jun 16 11:41:51 redorbita1 kernel: Key type cifs.idmap registered

Jun 16 11:41:51 redorbita1 automount[937]: mount_mount: mount(generic): mounted //192.168.1.155/data type cifs on /mnt/cifs_share/hare_data

Jun 16 11:41:51 redorbita1 automount[937]: dev_ioctl_send_ready: token = 1

Jun 16 11:41:51 redorbita1 automount[937]: mounted /mnt/cifs_share/hare_data

All the best

:wq!

Comments