27

I am currently using cifs to mount some network shares (that require authentication) in /etc/fstab. It works excellently, but I would like to move the authentication details (username/pass) outside of fstab and be able to chmod it 600 (as fstab can have issues if I were to change its permissions). I was wondering if it is possible to do this (many-user system, don't want these permissions to be viewable by all users).

from:

//server/foo/bar /mnt/bar cifs username=user,password=pass,r 0 0

to:

//server/foo/bar /mnt/bar cifs <link to permissions>,r 0 0

(or something analogous to this). Thanks.

TJ L
  • 514

4 Answers4

22

From the mount.cifs manpage:

credentials=filename
    specifies a file that contains a username and/or password. The format of the file is:

                         username=value
                         password=value
   This is preferred over having passwords in plaintext in a shared file, such as /etc/fstab. Be sure to protect any credentials file properly.

janneb
  • 3,949
9

Use the credentials option such as:

http://www.justlinux.com/nhf/Filesystems/Mounting_smbfs_Shares_Permanently.html

Example from the website:

cd
echo username=mywindowsusername > .smbpasswd
echo password=mywindowspassword >> .smbpasswd
chmod 600 .smbpasswd

Substitute your Windows username and password in the commands. No one else except root would be able to read the contents of this file.

Once that is created, you would modify the line in the /etc/fstab file to look like this:

//servername/sharename /mountdirectory smbfs credentials=/home/myhomedirectory/.smbpasswd 0 0

example from /etc/fstab:

//server/share/   /mnt/localmountpoint   cifs   credentials=/root/.creda

janneb's post and the link to man page show what needs to be present in the credentials file.

damorg
  • 1,266
6

So I'm accumulating both answers

  1. Create file, e.g. /root/.cifs

    username=value
    password=value
    domain=value (optional)
    
  2. set permission 600 (rw- permission) to protect your credentials

    # chmod 600 /root/.cifs
    
  3. pass credentials=/root/.cifs to your command instead of username= and password=

vladkras
  • 171
4

Could try cifscloak:

python3 -m pip install cifscloak

... and see the README at https://github.com/sudoofus/cifscloak

0xC0000022L
  • 1,576
  • 2
  • 24
  • 42