So I often use this command to mount a Samba share.

mount -t cifs //ip/share /mnt/backups -o username=user,password=pwd,domain=domain

I want to use a credentials file (with 600 permission) instead of typing in username/password.

Any ideas how this can be done? I've looked around and the only examples I've found are for using a credentials file if I want to auto-mount a Samba share using /etc/fstab.


1 Answer 1


you must use the argument credentials=

mount -t cifs //ip/share /mnt/backups -o credentials=/path/filename

quoting from man mount.cifs


specifies a file that contains a username and/or password and optionally the name of the workgroup. The format of the file is:


I suggest to create your file under /root/.smbcredentials_sharename with permission 600 as you already said.

Make sure NOT to have spaces around the = or you will get permission denied errors as the values are not correctly taken into account.

  • How do you handle it if the password has spaces? I tried enclosing it in double-quotes like password="my password is here" but it didn't like that.
    – raphael75
    Commented Jun 25, 2022 at 2:32
  • 1
    if it is possible i would change the password with one without spaces in it. Commented Jun 25, 2022 at 4:18

You must log in to answer this question.

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