18

I’m having a problem with fstab on Server 18.04. I’m trying to mount a number of Windows Server network shares. If I put the username and password into each line of fstab and do sudo mount -a, it works fine. However, when I try to use a “credentials” file, it all goes pear-shaped.

So this:

//server/share /mount/point cifs ro,auto,user=user,password=password 0 0

…works fine.

However, if I try this:

//server/share /mount/point cifs ro,auto,credentials=/etc/.smbcredentials 0 0

…with .smbcredentials containing the following:

user=username  
password=password  
domain=domain  

…this does not work. sudo mount -a -v outputs the following:

/ : ignored  
/boot/efi : already mounted  
none : ignored  
domain=mydomain  
,prefixpath=Projects/XYZ,pass=********.168.1.10,unc=\server\share,user=username  
mount error(13): Permission denied  
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)

168.1.10 is the partial IP address of the server on which the shares that I want to mount are located. It appears that the password is being concatenated onto the IP of the server.

So, what am I doing wrong? Any help would be much appreciated.

threnody
  • 181
  • Hi welcome to Ask Ubuntu! The credentials file is supposed to use username=username rather than user=.. though I can't see how that would cause this problem. Was that just a typo in the post? – Arronical Feb 20 '19 at 11:29
  • Hi, I've seen examples that use either user or username. I'm not sure if you can use either or only one or the other. Paul – threnody Feb 20 '19 at 11:33
  • Yeah, I've just tried it on a 14.04 server and you're correct. Either of them work. I'm afraid I don't have anything else to offer, hopefully someone more knowledgeable will be along to help. – Arronical Feb 20 '19 at 11:41
  • Long shot, but does the file /etc/.smbcredentials have the proper permissions and owner/group? Even though you are trying to mount as sudo. – Jos Feb 20 '19 at 11:42
  • 2
    A related post on Unix SE: https://unix.stackexchange.com/questions/124342/mount-error-13-permission-denied It mentions debugging the issue in dmesg and syslog. It might be due to the default sec being selected when using credentials. – Dan Feb 20 '19 at 11:57
  • @Dan That's a good point. FWIW I currently use sec=ntlmv2. – Jos Feb 20 '19 at 12:11
  • 1
    Does your credentials file have the correct (Unix-style) line terminations? or does it use Windows style CRLF? – steeldriver Feb 20 '19 at 12:28
  • Hi, .smbcredentials is owned by root and is rw for root only. – threnody Feb 20 '19 at 13:20
  • fstab and .smbcredentials I edited/created in Ubuntu with nano. – threnody Feb 20 '19 at 13:20

4 Answers4

13

My working credentials file is located in my ~ folder and looks like this

username=[username]
password=[password]

Its permissions are -rw------- and it is owned by my user.

The corresponding fstab line is

//[URL]/[sharename] /media/[mountpoint] cifs vers=3.0,credentials=/home/[username]/.sharelogin,iocharset=utf8,file_mode=0777,dir_mode=0777,uid=[username],gid=[username],nofail 0 0

I don't use "domain" but that doesn't mean that you don't need it.

  • Hi, I tried your suggested version - still can't get it to work with a credentials file. Thanks anyway! – threnody Feb 22 '19 at 14:31
  • Are you supplying the correct credentials? It works fine for me. – Organic Marble Feb 22 '19 at 14:33
  • This first gives an error mount: /etc/fstab: parse error at line 14 -- ignored and then after fixing what I think is .sharelogin to ,sharelogin it gives bad option uid="admin". Finally, you don't make any distinction between the local user login and the remote user login when filling in the credentials file so I'm not sure which one to use. – fIwJlxSzApHEZIl Feb 01 '20 at 23:57
  • @anon58192932 It's /home/[username]/.sharelogin and it works great for me. You need to supply credentials for the system you are trying to access, not the one you already have access to. If you have a new question, it's better to post it as such. However, if you comment with the exact syntax of your fstab line, I'll be glad to take a look at it. – Organic Marble Feb 02 '20 at 00:13
  • This answer assumes that username is the same on local and remote. At the very least, in the ~/.sharelogin file content, that username must be the remote username. Yet in the fstab line the /home/[username]/.sharelogin must be the local username. Thus we have no idea if uid=[username] is referring to the local user or the remote user and since the field is uid if we can pass a numeric value. – erwin Aug 05 '22 at 07:20
  • I have a follow-up question to this, how would the fstab line be written if you have multiple shares? I have like 10-15 SMB shares setup on one device, and I obviously don't want to have to list that many lines in the fstab. – Raleigh L. Aug 11 '22 at 08:33
  • @RaleighL. you make a mount for each folder you want in /mnt/ - if you want one, share the root; or, group accordingly. – Tom Dec 04 '22 at 03:18
  • It would be lovely to see some way of doing this without putting things such as a password in a plain text file. :D – rbaleksandar Jan 27 '25 at 04:49
8

Had same issue, check for errors with:

tail -f /var/log/kern.log

-- > kernel: [ 7917.935203] CIFS VFS: No username specified

$ sudo apt install cifs-utils

Fixed it for me..

JPronk
  • 81
  • Had a similer error in dmesg but fix was the same. Status code returned 0xc000006d STATUS_LOGON_FAILURE – Martin Oct 23 '23 at 18:09
  • 1
    +1. cifs-utils is a required package for the "credentials=" parameter to be recognized correctly by mount. – falken Jul 19 '24 at 08:58
0

I was having trouble mounting my QNAP NAS Samba share on Ubuntu 18.04 with a credentials file. Here's what worked for me after trying on and off for months.

  1. Find your Ubuntu username and create an identically named user with the password of your choice on your QNAP nas with the appropriate R/W permissions to your shared folder. So my username for Ubuntu is username so I created a user on QNAP called username and generated a random password with LastPass.
  2. Create a file to hold the Samba login credentials: nano ~/.samba_credentials
  3. Add the following lines:
username=your_shared_linx_and_qnap_username
password=the_qnap_user_password_you_chose
domain=WORKGROUP

Here's how mine looks:

username=username
password=last_pass_password
domain=WORKGROUP

The domain option might be optional but the default Windows 10 workgroup is WORKGROUP so this should work as long as you didn't change it. And if you did change it you probably know what a workgroup is and what value you changed it to.

  1. Create the folder where your share will mount locally. mkdir /media/username/storage
  2. Then edit your /etc/fstab file to auto-mount the QNAP Samba share via CIFS:
  3. //nas1da09d.local/files /media/username/storage cifs credentials=/home/username/.samba_credentials,uid=username,noperm,rw 0 0
-1

When mounting several smb drives with same credentials you have to create one credential file per mount. In other words, you can not use one credential file for several mounts.

Create a new file for each mount

sudo nano /etc/.smbcredentials1
sudo nano /etc/.smbcredentials2
sudo nano /etc/.smbcredentials3

add your credentials to each file

username=username
password=password
domain=WORKGROUP

then chmod the files for protection

sudo chmod 0600 .smbcredentials1 .smbcredentials2 .smbcredentials3 

then use each file as credantials for each mount sudo nano /etc/fstab

//server/share /mount/point cifs ro,auto,credentials=/etc/.smbcredentials1 0 0
//server/share /mount/point cifs ro,auto,credentials=/etc/.smbcredentials2 0 0
//server/share /mount/point cifs ro,auto,credentials=/etc/.smbcredentials3 0 0

then mount

sudo mount -a -v

this will probably solve your issue.