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:
    tim@ubuntu-server:~$ cd /root
    tim@ubuntu-server:/root$ su
    root@ubuntu-server:~# echo username=username > .smbpasswd
    root@ubuntu-server:~# echo password=password >> .smbpasswd
    root@ubuntu-server:~# cat .smbpasswd
  2. Now you want to protect this file so that only root can read it:
    root@ubuntu-server:~# chmod 400 .smbpasswd
    root@ubuntu-server:~# ls -al .smbpasswd
    -r-------- 1 root root 36 2009-07-21 00:24 .smbpasswd
  3. Open /etc/fstab in a text editor (make sure you’re root still!)
    root@ubuntu-server:~# cd /etc
    root@ubuntu-server:/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:
    root@ubuntu-server:/etc# mount -a
  6. That’s it, you should now have your drive available!

Leave a Reply

  • (will not be published)