Hi
This HOWTO shows you how to Automount SMB shares so that they are active whenever you log in without using FSTAB.
Firstly the background.
I bought a nice network attached storage (NAS) device. I setup two shares on it one called HOUSEHOLD and one called DATA. DATA needed a username and password. HOUSEHOLD did not.
I wanted mount these shares automatically every time I logged on so that they were available within KDE. I didn't want to have to enter the username/password details every time.
No FSTAB!
I gave up on the normal approach to automounting using FSTAB. Largely because I am convinced by other posts and my own troubles that the FSTAB may be loaded in a poorly chosen order within Kubuntu 7.04 Feisty Fawn.
Neil P gave me this link: http://www.penguin.ch/dokuwiki/doku....tab#a_bad_joke
that supports this conclusion.
0>
I'm not a mind reader. Of course you are going to have to customize it for your system. So I'll use values in angled brackets rather than my own paths. Here they are:
uid=1000,gid=1000 chances are your login is the default id number. If not where you see these, enter your own uid and gid values.
<username> means your login username. For the examples I'll use: 'myname'
<pathto> means the path to. For the example I'll put the mount points in /home/<username>/
<server> means the server the share is on. For me this is 10.0.0.5, you might choose to use the hostname or a different IP.
<shareUsername> means the share username. For the example I will use 'nasprivate'
<sharePassword> means the share password. For the example I will use 'naspass'
<mountpointData> means the folder the DATA share will be mounted on. (newbies don't sweat, it is easy). For the example I'll use 'nasDATA'
<mountpointHousehold> means the folder the HOUSEHOLD share will be mounted on. (newbies don't sweat, it is easy). For the example I'll use 'nasHOUSEHOLD'
<shareName1> means the network share. For the example this is the DATA folder mentioned above.
<shareName2> means the network share. For the example this is the HOUSEHOLD folder mentioned above.
# normally means a comment. This case I have prefixed all commands with one, to stop mindless copy and paste. The examples need to be edited to your system.
1>
Ok so lets make sure you have everything installed.
First what is installed? I searched for 'smb' with and cleared the 'not installed' filter in Adept Manager.
Those are what I had installed (I had manually installed smbfs via Adept earlier). If you have the same it *should* be ok. If not you may want to install the above.
2>
Feeling brave? Ok here is everything in one shot, no examples.
Next restart the system and setup any shortcuts/links to the folders as you see fit.
WTF? Not so confident? No problem. Step by step with full explanations are next.
STEP BY STEP
A>
Create some mount points. Most people will use their home directory I guess.
i.e.
What this does is change to the directory and create the directory's we will mount the shares on.
B>
Next create the entry that KDE will autostart. We're calling the actual script 'mountNAS.sh'
i.e.
C>
Now we need to fill in the script:
i.e.
Ok lets pause and explain this one. We're simply putting some text in the mountNAS.sh file we just created. You may find it easier to open the file and enter it directly. If so this is the data that is entering:
D>
We need to give the file we just created execute permissions.
This bit doesn't need an example. It is as it is. You could use:
# sudo chmod 755 ~/.kde/Autostart/mountNAS.sh
if you prefer.
E>
The problem now is that the sudo command needs us to input a password. So lets get to that:
i.e.
All this does is open up the file:
and add:
to the end of it. This should allow us to use sudo with that smbmount command, in that script without entering the password. (I think... corrections welcome).
F>
Thats it. Just restart. Once loaded navigate to
/<pathto>/<mountpointData>/
to see if it displays the contents on the network share. It does! Great. Job done.
EXTRA NOTES:
The username and password for the NAS shares are stored in plain text within the mountNAS.sh file that is autostarted. For me this is no big deal I'm on a trusted network. For others this may be deemed as a security problem.
Desktop shortcuts:
You may want to right click on the desktop and
Create New'>'Link to location
Then you can choose a shortcut name, set the location as:
/<pathto>/mountpointData/
i.e.
/home/myname/nasDATA/
You can also set the icon to something more entertaining.
Also note: this approach won't work if logging in as a different user and probably not work if you log in using a different desktop.
As regards all this I can only say 'it works for me', use at your own risk, etc.
Regards,
Matthew Newton
Corrections/feedback welcome.
Edit: Corrected sudoers file entry segment.
Edit: Added uid=1000 and gid=1000 explanations with starting notes.
This HOWTO shows you how to Automount SMB shares so that they are active whenever you log in without using FSTAB.
Firstly the background.
I bought a nice network attached storage (NAS) device. I setup two shares on it one called HOUSEHOLD and one called DATA. DATA needed a username and password. HOUSEHOLD did not.
I wanted mount these shares automatically every time I logged on so that they were available within KDE. I didn't want to have to enter the username/password details every time.
No FSTAB!
I gave up on the normal approach to automounting using FSTAB. Largely because I am convinced by other posts and my own troubles that the FSTAB may be loaded in a poorly chosen order within Kubuntu 7.04 Feisty Fawn.
Neil P gave me this link: http://www.penguin.ch/dokuwiki/doku....tab#a_bad_joke
that supports this conclusion.
0>
I'm not a mind reader. Of course you are going to have to customize it for your system. So I'll use values in angled brackets rather than my own paths. Here they are:
uid=1000,gid=1000 chances are your login is the default id number. If not where you see these, enter your own uid and gid values.
<username> means your login username. For the examples I'll use: 'myname'
<pathto> means the path to. For the example I'll put the mount points in /home/<username>/
<server> means the server the share is on. For me this is 10.0.0.5, you might choose to use the hostname or a different IP.
<shareUsername> means the share username. For the example I will use 'nasprivate'
<sharePassword> means the share password. For the example I will use 'naspass'
<mountpointData> means the folder the DATA share will be mounted on. (newbies don't sweat, it is easy). For the example I'll use 'nasDATA'
<mountpointHousehold> means the folder the HOUSEHOLD share will be mounted on. (newbies don't sweat, it is easy). For the example I'll use 'nasHOUSEHOLD'
<shareName1> means the network share. For the example this is the DATA folder mentioned above.
<shareName2> means the network share. For the example this is the HOUSEHOLD folder mentioned above.
# normally means a comment. This case I have prefixed all commands with one, to stop mindless copy and paste. The examples need to be edited to your system.
1>
Ok so lets make sure you have everything installed.
First what is installed? I searched for 'smb' with and cleared the 'not installed' filter in Adept Manager.
Code:
libsmbclient smbclient smbfs xsmbrowser
2>
Feeling brave? Ok here is everything in one shot, no examples.
Code:
# cd /<pathto>/<username> # sudo mkdir <mountpointData> # sudo mkdir <mountpointHousehold> # sudo touch /home/<username>/.kde/Autostart/mountNAS.sh # sudo echo -e '#!/bin/bash\nsudo smbmount //<server>/<shareName1> /<pathto>/<username>/<mountpointData> -o username=<shareUsername>,password=<sharePassword>,uid=1000,gid=1000,mask=000,rw;\nsudo smbmount //<server>/<shareName2> /<pathto>/<mountpointHousehold> -o uid=1000,gid=1000,mask=000,rw;\nexit 0;' > /home/<username>/.kde/Autostart/mountNAS.sh # sudo chmod a+x ~/.kde/Autostart/mountNAS.sh # sudo echo -e '<username> ALL=NOPASSWD:/usr/bin/smbmount' >> /etc/sudoers
WTF? Not so confident? No problem. Step by step with full explanations are next.
STEP BY STEP
A>
Create some mount points. Most people will use their home directory I guess.
Code:
# cd /<pathto>/<username> # sudo mkdir <mountpointData> # sudo mkdir <mountpointHousehold>
Code:
# cd /home/myname/ # sudo mkdir nasDATA # sudo mkdir nasHOUSEHOLD
B>
Next create the entry that KDE will autostart. We're calling the actual script 'mountNAS.sh'
Code:
# sudo touch /home/<username>/.kde/Autostart/mountNAS.sh
Code:
# sudo touch /home/myname/.kde/Autostart/mountNAS.sh
Now we need to fill in the script:
Code:
# sudo echo -e '#!/bin/bash\nsudo smbmount //<server>/<shareName1> /<pathto>/<username>/<mountpointData> -o username=<shareUsername>,password=<sharePassword>,uid=1000,gid=1000,mask=000,rw;\nsudo smbmount //<server>/<shareName2> /media/smbhousehold -o uid=1000,gid=1000,mask=000,rw;\nexit 0;' > /home/<username>/.kde/Autostart/mountNAS.sh
Code:
# sudo echo -e '#!/bin/bash\nsudo smbmount //10.0.0.5/DATA /home/myname/nasDATA -o username=nasprivate,password=naspass,uid=1000,gid=1000,mask=000,rw;\nsudo smbmount //10.0.0.5/HOUSEHOLD /home/myname/nasHOUSEHOLD -o uid=1000,gid=1000,mask=000,rw;\nexit 0;' > /home/myname/.kde/Autostart/mountNAS.sh
Code:
#!/bin/bash sudo smbmount //10.0.0.5/DATA /home/myname/nasDATA -o username=nasprivate,password=naspass,uid=1000,gid=1000,mask=000,rw; sudo smbmount //10.0.0.5/HOUSEHOLD /home/myname/nasHOUSEHOLD -o uid=1000,gid=1000,mask=000,rw; exit 0;
We need to give the file we just created execute permissions.
Code:
# sudo chmod a+x ~/.kde/Autostart/mountNAS.sh
# sudo chmod 755 ~/.kde/Autostart/mountNAS.sh
if you prefer.
E>
The problem now is that the sudo command needs us to input a password. So lets get to that:
Code:
# sudo echo -e '<username> ALL=NOPASSWD:/usr/bin/smbmount' >> /etc/sudoers
Code:
# sudo echo -e 'myname ALL=NOPASSWD:/usr/bin/smbmount' >> /etc/sudoers
Code:
/etc/sudoers
Code:
myname ALL=NOPASSWD:/usr/bin/smbmount
F>
Thats it. Just restart. Once loaded navigate to
/<pathto>/<mountpointData>/
to see if it displays the contents on the network share. It does! Great. Job done.
EXTRA NOTES:
The username and password for the NAS shares are stored in plain text within the mountNAS.sh file that is autostarted. For me this is no big deal I'm on a trusted network. For others this may be deemed as a security problem.
Desktop shortcuts:
You may want to right click on the desktop and
Create New'>'Link to location
Then you can choose a shortcut name, set the location as:
/<pathto>/mountpointData/
i.e.
/home/myname/nasDATA/
You can also set the icon to something more entertaining.
Also note: this approach won't work if logging in as a different user and probably not work if you log in using a different desktop.
As regards all this I can only say 'it works for me', use at your own risk, etc.
Regards,
Matthew Newton
Corrections/feedback welcome.
Edit: Corrected sudoers file entry segment.
Edit: Added uid=1000 and gid=1000 explanations with starting notes.
Comment