Visit Our UNIX and Linux User Community

Script to mount nas-share using generated credentials (mount EC 13,32)

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to mount nas-share using generated credentials (mount EC 13,32)
# 1  
Old 02-11-2014
Script to mount nas-share using generated credentials (mount EC 13,32)


At home i have 1 nas with 3 shares, of which i used to mount 2 of them using a script with hardcoded password and username in it.

EDIT: Turns out, its not the script, but 'how i access' the nas share.. (-o user=XY,password=... VS. -o credentials=...).

Figured about credential files, on a home computer, i tried to match this task into a script.
Idea is to provide all infos at the first time, like:
[sea@localhost ~]$ mount_nas 

mount_nas (0.1)
Usage:		mount_nas //IP/SHARE /mount/point [username password [domain]]
Example:	mount_nas // /home/sea/net/pub sea ABCDEFG localdomain

Once configured, simply call:
		mount_nas SHARENAME
		Where SHARENAME will be the credential filename, and was 'generated' from //IP/SHARENAME...

In practice, it mounts the public one, but wont the private one (error codes: 13 & 32).
The 2 handling scripts are these:
PHP Code:
sudo umount 
/home/sea/priv/nas  /home/sea/net/pub
|grep 192 
export LC_ALL=C

source ~/.config/user-dirs.dirs

# The creation and usage of the credentials work fine...
#mount_nas //$IP/Public $XDG_PUBLICSHARE_DIR $USR $PW $DOM
#mount_nas //$IP/priv $XDG_CLOUD_DIR $USR $PW $DOM

# Thus, use the benefit of the script
echo;echo; mount_nas Public
echo;echo; mount_nas priv


During the 'tests' both shares have the same password, but for some reason, one gets mounted the other not.

umount: /home/sea/priv/nas: nicht eingehängt

Loaded settings: Public (//
0 Mounted: /home/sea/net/pub (//

Loaded settings: priv (//
mount error(13): Permission denied
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)
32 Failed: /home/sea/priv/nas (//

// on /home/sea/net/pub type cifs (rw,relatime,vers=1.0,cache=strict,username="MYUSERNAME",domain="MYDOMAIN",uid=0,noforceuid,gid=0,noforcegid,addr=,unix,posixpaths,serverino,acl,rsize=1048576,wsize=65536,actimeo=1)

[sea@localhost ~]$ clear ; umnt-nas ; mnt-nas ; echo ; mount|grep 192 ; echo

The actual script is: mount_nas
PHP Code:
export LC_ALL=C
#    Author:     sea (Simon Arjuna Erat)
#    Contact:
#    Created:    2014.17.11
#    Description:    If all required variables (2-3) are provided, it creates
#            a credentials file which it'll be using at 2nd usage,
#            if you just pass the sharename of an already used NAS entry.
#        NOTE:    There must be no identical names on diffrent NAS!
#    Variables
ME=$(basename $0)
source ~/.config/user-dirs.dirs
="\n$ME ($script_version)\nUsage:\t\t$ME //IP/SHARE /mount/point [username password [domain]]
$ME //$(for STR in [a-z];do ip addr|awk '{print $2}'|grep ^$STR -A2|grep -iv ::|grep -iv 127|grep [0-9].[0-9].[0-9]|sed s,"/"," ",g|awk '{print $1}';done)/Public $XDG_PUBLICSHARE_DIR $USER ABCDEFG $(hostname|sed s,'\.',' ',g|awk '{print $2}')\n\nOnce configured, simply call:\n\t\t$ME SHARENAME\n\t\tWhere SHARENAME will be the credential filename, and was the full //IP/SHARENAME...\n"
[ ! -"$NAS_CFG_DIR] && mkdir -"$NAS_CFG_DIR
$1" ; MP="$2" ; CREDS=""
#    Arguments : pre-check
    [ -f "
$NAS_CFG_DIR/$1" ] && doneConfig=true || doneConfig=false
#    Error messages
    [ -z $1 ] && echo -e "
$hlp_txt" && exit 1
$(basename $1)"
    export this_cred="
    [ -z $2 ] && ( [ -f "
$NAS_CFG_DIR/$1" ] && doneConfig=true || doneConfig=false )
    [ ! -z $3 ] && [ -z $4 ] && echo -e "
$hlp_txt" && exit 1
    [ ! 
$doneConfig ] && [ -z $2 ] && echo -e "$hlp_txt" && exit 1
#    Arguments : prepare credentials
    if [ ! 
$doneConfig ]
    then    # Configuration is missing
        touch "
        printf "
# NAS ($NAS) Credentials file, created by sea ($(date +'%Y-%m-%d'))\nusername=\"$3\"\npassword=\"$4\"\ndomain=\"$5\"\nadress=\"$1\"\nmountpoint=\"$2\"" > "$this_cred"
export CREDS="-o credentials=$this_cred"
elif $doneConfig ]
then    # Configuration exists
export CREDS="-o credentials=$this_cred"    
else    # Use plain text, not credentials file
[ ! -$] && CREDS="username=$3"
[ ! -$] && CREDS="$CREDS,password=$4"
[ ! -$] && CREDS="$CREDS,domain=$5"
[ ! -$] && CREDS="-o $CREDS"
export CREDS
if echo $CREDS|grep credentials > /dev/zero
    then    printf 
"Loading settings: $1\r"
source "$this_cred&& \
NAS="$adress&& \
echo "Loaded settings: $1 ($NAS)"
#    Action
if sudo mount -t cifs $NAS $MP $CREDS
echo "$? Mounted: $MP ($NAS)"
else     echo "$? Failed: $MP ($NAS)"
#    Reset variables
export MP CREDS NAS ANSWER doneConfig this_cred NAS_NAME 
Trying to mount the 'missing' share manualy and the regarding credential file is looking like:
[sea@localhost ~]$ CREDS="/path/to/creds";sudo mount // -t cifs /mnt/sysimage/ -o credentials="$CREDS" ; echo $? ; cat $CREDS
mount error(13): Permission denied
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)
# NAS (// Credentials file, created by sea (2014-02-11)
[sea@localhost ~]$ sudo mount // -t cifs /mnt/sysimage/ -o credentials="$CREDS" ; echo $? ; cat $CREDS

Any ideas apreciated.
Thank you in advance
- Simon

---------- Post updated at 10:28 ---------- Previous update was at 06:35 ----------

Just to be sure i'm trying to mount an existing share...
[sea@localhost net]$ smbclient -L -N
Domain=[OCEAN] OS=[Unix] Server=[Samba 3.5.6]

	Sharename       Type      Comment
	---------       ----      -------
	IPC$            IPC       IPC Service (Terra Nova)
	Public          Disk      
	priv            Disk      
	TimeMachine     Disk      
Domain=[OCEAN] OS=[Unix] Server=[Samba 3.5.6]

But its kidding with me...
sudo mount -t cifs // /mnt/nas/ -o user=USERNAME,password=PASSWORD,domain=DOMAIN

Works like a charm, while
sudo mount -t cifs // /mnt/nas/ -o credentials="/home/sea/.config/script-tools/nas/priv"

results in the 'plain and known error':
mount error(13): Permission denied
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)

How the credentials file looks like is shown in the first post...
Of couse, password, username and domain are verified.

Anything i missed?
Any ideas please?

---------- Post updated at 11:15 ---------- Previous update was at 10:28 ----------

Also tried:
chmod [644|400] /path/of/cred

As well as:

Digging deeper than google's 2nd page, reading the repeating solutions (if even) is quite disencouraging.

[37395.259096] SELinux: initialized (dev cifs, type cifs), uses genfs_contexts
[37395.368390] CIFS VFS: cifs_mount failed w/return code = -13

[sea@localhost nas]$ mnt-nas 

0 Loaded settings: Public (//
Credential formatted incorrectly: (null)
Credential formatted incorrectly: "//"
Credential formatted incorrectly: "/home/sea/net/pub"
mount.cifs kernel mount options: ip=,unc=\\\Public,iocharset=utf8,file_mode=0777,dir_mode=0777,sec=ntlm,user="simon",,domain="ocean",pass=********
0 Mounted: /home/sea/net/pub (//

0 Loaded settings: priv (//
Credential formatted incorrectly: //
Credential formatted incorrectly: /home/sea/priv/nas
mount.cifs kernel mount options: ip=,unc=\\\priv,iocharset=utf8,file_mode=0777,dir_mode=0777,sec=ntlm,user="simon",,domain="ocean",pass=********
mount error(13): Permission denied
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)
32 Failed: /home/sea/priv/nas (//

I really dont get it Smilie
Both shares share the same uid/pw combination, they just differ by the Sharename.
Ok, the credential file is formatted incorrectly.. both times, but only one doesnt work.

If both would not work, i'd sure say its because i stored the full-adress (//IP/sharename) as well as the mountpoint (/home/sea/priv/nas).
But since 1 of 2 work, me back at the beginning... :clueless:

Last edited by sea; 02-11-2014 at 07:39 AM..

Previous Thread | Next Thread
Test Your Knowledge in Computers #715
Difficulty: Easy
A stored-program computer is a computer that stores program instructions on external hard drives..
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Passing User Credentials with Mount Command

My HP-UX server currently mounts a directory on a Windows 2012 server. The Windows server allows anonymous connections for RW and this configuration has worked well for years. Now, due to tightening security requirements I can't use anonymous. I also can't setup Identity Mapping on the Windows... (5 Replies)
Discussion started by: jduehmig
5 Replies

2. Shell Programming and Scripting

Mount NFS Share On NFS Client via bash script.

I need a help of good people with effective bash script to mount nfs shared, By the way I did the searches, since i haven't found that someone wrote a script like this in the past, I'm sure it will serve more people. The scenario as follow: An NFS Client with Daily CRON , running bash script... (4 Replies)
Discussion started by: Brian.t
4 Replies

3. UNIX for Dummies Questions & Answers

NFS mount of Windows NAS

The UPS connected to the Disk Array portion of my Windows 2003 NAS burned up over the weekend. Reconnected it to a new UPS and re-booted the NAS box. Since then I have not been able to get my HPUX 10.2 box to mount the shared drives on the NAS. At boot, the NFS client & server subsystems do a... (0 Replies)
Discussion started by: twalker0
0 Replies

4. UNIX and Linux Applications

Virtualbox Need to change share folder name before i can mount it

HI I would like to ask about my virtualbox 4.0.4 in my lucyd lynx box My shared forlder isn't auto mount in my linux guest OS. And everytime i manually mount using command sudo mount -t vboxsf <shared_folder_name> <Guest_location> it throw an error msg "/sbin/mount.vboxsf: mounting failed... (1 Reply)
Discussion started by: jao_madn
1 Replies

5. Solaris

mount windows share folder

all,,i need help,,i try to mount a windows 2000 share folder to my system,,i already userd smb mount,mount -F and bunch of stuff and none is working,,can anyone give me a script to this?? PS : when i use mount -F i got this message : nfs mount: insufficient privileges ,,, is it must be root ? (6 Replies)
Discussion started by: Cellscript
6 Replies

6. IP Networking

Can't see home folder on one NFS mount but can in another mount on another share

Hello, I have a few Ubuntu 9.10 laptops I'm trying to learn NFS sharing with. I am just experimenting on this right now, so no harsh words about the security of what I'm playing with, please ;) Below are the configs /etc/exports on host /home/woodnt/Homeschool... (2 Replies)
Discussion started by: Narnie
2 Replies

7. Solaris

how to mount Windows NFS share on solaris

Hi, How can i mount an NFS share on a solaris machine a filesystem ? I have enabled nfs on a windows server and the shares has given read/write access to it to all the users. I would like to mount it on around 10 different solaris boxes with different versions of solaris. Thanks in advance. (2 Replies)
Discussion started by: uxadmin007
2 Replies

8. Solaris

solaris 10 errors mount external usb Harddisk zfs on a nas without cdrom

Hi, I try to mount an external USB HD on a solaris 10 without any success. Machine hardware: i86pc OS version: 5.10 Processor type: i386 Hardware: i86pc The HD is a zfs, but I installed this with a Ubuntu 8.10. iostat -En displays this: --> so the system... (0 Replies)
Discussion started by: edubidu
0 Replies

9. UNIX for Advanced & Expert Users

Compressing files on NAS mount

Hello, I am having difficulty compressing the files using compress or GZIP utility on NAS share NFS mounted on my linux server. Any one have idea on how to do this ? I get the followign error but the trying to compress the files STRP2> compress STR_OUTBOUND_CDM_LOG_LOB.PRT2008_26.txt... (1 Reply)
Discussion started by: kamathg
1 Replies

10. UNIX for Advanced & Expert Users

Mount Linux share onto Sco 5.0.6

I've got a Sco 5.0.6 box and an Ubuntu box on my network. i want to backup certain directories onto a share on the Ubuntu box. how do i mount a linux share onto the Sco box? (1 Reply)
Discussion started by: sall
1 Replies

Featured Tech Videos