Posted by & filed under Linux.

To map a remote samba share in Linux with read-write access and a username and password, you will require samba. In debian based distros, this is easily obtained via sudo apt-get install samba.

  1. Create a secure credentials file:
    [email protected]:~$ cd /root
    [email protected]:/root$ su
    Password:
    [email protected]:~# echo username=username > .smbpasswd
    [email protected]:~# echo password=password >> .smbpasswd
    [email protected]:~# cat .smbpasswd
    username=username
    password=password
    
  2. Now you want to protect this file so that only root can read it:
    [email protected]:~# chmod 400 .smbpasswd
    [email protected]:~# ls -al .smbpasswd
    -r-------- 1 root root 36 2009-07-21 00:24 .smbpasswd
    [email protected]:~#
    
  3. Open /etc/fstab in a text editor (make sure you’re root still!)
    [email protected]:~# cd /etc
    [email protected]:/etc# joe fstab
    
  4. Add a similar line to the end of the file (don’t forget to leave blank line at the bottom!)
    //serverip/sharename  /mnt/path/filedrive    smbfs    credentials=/root/.smbpasswd  0       0
    
  5. Now just tell the system to mount all points defined in fstab:
    [email protected]:/etc# mount -a
    
  6. That’s it, you should now have your drive available!

Leave a Reply

  • (will not be published)