NI Linux Real-Time Discussions

Showing results for 
Search instead for 
Did you mean: 

Samba share using credentials file.

Go to solution

Maybe this is more of a general linux question but I'll give it a shot here.

I want to mount a Windows Network shared drive to my cRIO 9038.

I've installed samba and cifs-utils with opkg.

I wiped out the original smb.conf and replaced it with the following


workgroup = WORKGROUP
security = USER
encrypt passwords = yes
smb ports = 445 139

comment = COMMENT
browseable = yes
valid users = admin
admin users = admin
path = /mnt/data/
writeable = yes
force create mode = 0770
locking = yes

I then used the following to add my stock admin user and restart samba..

smbpasswd -L -a admin
smbpasswd -L -e admin
/etc/init.d/samba restart

next, I tested mounting using 

mount //mynetworkshare /mnt/data -o username=myusername, password=mypassword

This works.

Now, I create a credential file that contains this text


i then attempt to run

mount //mynetworkshare /mnt/data -o credentials=[credentialfile]

I get a mount error stating permission denied.


I ran the command again verbosely and the parsed command is printed. I noticed that it has user=admin instead of the username in my credential file.


I'm now wondering if I have some confusion with how usernames work in samba.


I've added admin as a user to Samba. I assumed this was for local access to samba shared drives. I am under the understanding that the credential file, used this way, is grabbing the credentials to access the network resource.


The fact that the verbose output shows user=admin makes me believe that it is not seeing that my file contains the username= key and is instead using the default which is the environmental variable USERNAME.


**  Side note, I tried to check the environmental variable and noticed that printenv doesn't exist in this distro. google didn't help me with this one... **

0 Kudos
Message 1 of 4
Accepted by topic author MPCC

I figured it out. The username that you'd like to use from the credential file must be specified.


mount -t cifs [remotepath] [mountpoint] -v -o credentials=[credentialfile],user=[myuser]

Also, I've added the following to fstab and it works. (Verified with mount -a)

[networklocation] [mountpoint] cifs credentials=[credentialfile],user=[myusername] 0 0
Message 2 of 4



First, what versions of the NI Software are you using when working with the Windows share?


Now, regarding what you've posted, a few points/questions: do you intend on further sharing the mount location from your cRIO? Shares described in the smb.conf are meant to be shared from your Linux machine. This also applies to the smbpasswd stuff that you're doing (this is creating credentials that are meant to be used when other SMB-capable clients connect to your Linux machine).


Now, regarding what you're seeing on the mount attempt, really, we kinda need to see what version of the OS you're using. Now, I was able to largely recreate the setup you want to use by mounting a local Windows share from my 9068 sitting at my desk (I needed to add the domain= entry as well), and I (out of habit) explicitly specified the mount type to force it to be cifs, but it worked fine with the 2017 version of the OS and software.


admin@crispus-attux:~# mount -v -t cifs //********/temp /mnt/network/ -o credentials=/mnt/creds
mount.cifs kernel mount options: ip=***.***.***.***,unc=\\********\temp,user=bm*****,,domain=*****,pass=********

admin@crispus-attux:~# cat /mnt/creds

And I did a cursory check of the /mnt/network/ folder, it looks correct and I'm able to open a file.


One unfortunate aspect of working with Windows shares is that it can change from Windows release to the next, and even within one version, dependent on how the share is setup. You may need to work with whoever's responsible for the share to help troubleshoot things from the server side (I mean, once we figure out why mount is attempting to just use the $USER environment variable over what's defined in your credentials file).


Finally, for the NI Linux RT distro, use env to get a listing of the environment variables. If you want printenv, it seems that this utility is part of the coreutils package (much of which is replaced by busybox on NI Linux RT)

Message 3 of 4

Ah, seems you've beaten me to answer your own question 😄 Hopefully some of the notes that I'd added to the response will nonetheless be useful to you (and others)

Message 4 of 4