14

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.

9
  • 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, 2019 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, 2019 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, 2019 at 11:41
  • 2
    A related post on Unix SE: unix.stackexchange.com/questions/124342/… 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, 2019 at 11:57
  • 1
    Does your credentials file have the correct (Unix-style) line terminations? or does it use Windows style CRLF? Feb 20, 2019 at 12:28

4 Answers 4

11

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.

7
  • Hi, I tried your suggested version - still can't get it to work with a credentials file. Thanks anyway!
    – threnody
    Feb 22, 2019 at 14:31
  • Are you supplying the correct credentials? It works fine for me. Feb 22, 2019 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. Feb 1, 2020 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. Feb 2, 2020 at 0: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 5, 2022 at 7:20
1

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..

1
  • Had a similer error in dmesg but fix was the same. Status code returned 0xc000006d STATUS_LOGON_FAILURE
    – Martin
    Oct 23, 2023 at 18:09
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.

2
  • 3
    There is no reason to create a different credential file for each mount. I use one file for three differnet mounts and it works perfectly well. Nov 25, 2020 at 14:52
  • Yeah, this is wrong. I use the same file for 3 different mounts. Mar 13, 2022 at 12:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .