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-commonDebian and derivatives:
Bash
[root@redorbita1 hare_data]# apt-get install autofs samba-clientNext 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 –ghostLet'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/dataAnd 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.cifswe restart the service
Bash
[root@redorbita1 hare_data]# service autofs restartWe 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.txtWe 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_dataAll the best
:wq!
Comments