After three days of hacking together mount commands finally my NAS is connected so that it can be accessed from terminal.
The script’s purpose is to mount a networked attached file store using terminal with the correct read and write attributes.
1: ################################################################ 2: # Author : Robert Lutken 3: # E-mail : [email protected] 4: # Date : Sat, 15-02-2014 5: # File Name : nasmount.sh 6: # Purpose : To connect to NAS 7: # Version : 1.0 8: # Notes : Unsecure version should not be used in 9: # volitile domains 10: # 11: ################################################################# 12: 13: #!/bin/bash 14: 15: ## The user name of the account on remote device i.e. admin 16: username=yourusername 17: 18: ## The Password of the user's account on remote device 19: password=yourpasword 20: 21: 22: ## The source location of the server and the share directory. 23: ## In order to mount you should ensure that /etc/nsswitch.conf apears as so: 24: ## hosts: files mdns4_minimal wins [NOTFOUND=return] dns mdns4 25: ## The order is important ! 26: ## and that winsbind is installed -> sudo apt-get install winbind 27: ## 28: ## If it isn't then you may use the IP address of the local server 29: 30: mountSRC=//nameofserver/sharedirectory 31: 32: ## The local directory of where the shared folder should be mounted i.e. /mnt/myshare. 33: ## This will need to be created i.e. sudo mkdir /mnt/myshare 34: mountDST=/wheretomount/share 35: 36: ## Finally the command that put's it all together with relvent read and write permissions. 37: sudo mount -t cifs $mountSRC $mountDST -o username=$username,password=$password,iocharset=utf8,file_mode=0777,dir_mode=0777 38: 39:
There is however an inherent security issue with this script as it stores passwords in plain text.
I would recommend that the use of a credentials file is used :
sudo nano $HOME/Desktop/CIFSCRED
All this file should contain is :
username=yourusername password=yourpassword domain=servername
Press CTRL+X and enter Y and Return to save
The file should then be restricted by using :
sudo chmod 0440 $HOME/Desktop/CIFSPWD
Finally the original script can be updated to
1: ################################################################ 2: # Author : Robert Lutken 3: # E-mail : [email protected] 4: # Date : Sat, 15-02-2014 5: # File Name : nasmount.sh 6: # Purpose : To connect to NAS 7: # Version : 1. 8: # Notes : This version uses a credentials file 9: # which should be secured using : 10: # 11: # sudo chmod 0440 myPasswordFile 12: # 13: ################################################################# 14: 15: #!/bin/bash 16: 17: myCredentials=$HOME/Desktop/CIFSPWD 18: 19: ## The source location of the server and the share directory. 20: ## In order to mount you should ensure that /etc/nsswitch.conf apears as so: 21: ## hosts: files mdns4_minimal wins [NOTFOUND=return] dns mdns4 22: ## The order is important ! 23: ## and that winsbind is installed -> sudo apt-get install winbind 24: ## 25: ## If it isn't then you may use the IP address of the local server 26: 27: mountSRC=//nameofserver/sharedirectory 28: 29: ## The local directory of where the shared folder should be mounted i.e. /mnt/myshare. 30: ## This will need to be created i.e. sudo mkdir /mnt/myshare 31: mountDST=/wheretomount/share 32: 33: ## Finally the command that put's it all together with relvent read and write permissions. 34: sudo mount -t cifs $mountSRC $mountDST -o credentials=$myCredentials,iocharset=utf8,file_mode=0777,dir_mode=0777 :