1

Not sure how mount works with CentOS, but I have a drive accessed through my CentOS file explorer at the path:

smb://ipaddress/sharedfoldername

And want to permanently mount it to my PC at /mnt/ or at /home/user/desktop but the following commands are probably wrong but could someone tell me how to get the machine to connect to the address and mount it to the place I want it on startup/login?

These commands are probably wrong but it's just what I assumed would do the trick:

sudo mount smb:/ipaddress/sharedfoldername /mnt/

Obviously replacing ipaddress with my actual IP ADDRESS and replacing sharedfoldername with my real shared drive name. - But.... it doesn't work - it tells me that smb doesn't work...?... and also says I may have got the mount command wrong too because it brings up mount help...?

It is accessable from CentOS if I access the path smb://ipaddress/sharedfoldername but I would like it mounted to a specific folder...

Any help would be greatly appreciated. Thanks.


SUBQUESTION

Why is _netfs not recognised if you look at the command for fstab in @jsbillings comment?

ekv_56
  • 57

1 Answers1

4

The smb:// URL indicator is just for the file browser, it's not an actual mount path you can use with mount.

Try using something like this:

mount -t cifs //ipaddress/sharedfoldername /mnt --verbose -o user=username

A cifs mount would probably be best if you used a credentials file rather than hard-code a username and password into /etc/fstab -- a file readable by all users on the system. You'd add a line something like this(one long line):

//ipaddress/sharedfoldername /mnt cifs credentials=/etc/smbcredentials,uid=1001,gid=1001,_netdev 0 0

And then create a file called /etc/smbcredentials that has this in it:

username=msusername
password=mspassword

(each on their own line)

Stephen Kitt
  • 434,908
jsbillings
  • 24,406
  • You're really helping me out today! - Thanks, I'll have a go. – ekv_56 May 29 '20 at 06:23
  • sudo mount -t cifs //ipaddress/sharedfoldername /mnt --verbose -o user=(username),pass=(password) worked. Just wondering if you know how to mount to the desktop etc. I tried the same commadn but changing /mnt/ to /home/username/Desktop but It didn't seem to do anything. I also realise the command doesn't mount permanently but I have set it to run on startup. Thanks – ekv_56 May 29 '20 at 08:11
  • If I try to mount to Desktop/Documents etc. it says I have mounted it but nothing appears in those folders.....? – ekv_56 May 29 '20 at 09:51
  • @ORICKETTS you probably want to also add uid and gid to the mout options. If you want it to mount on boot, you need to add it to /etc/fstab (using the correct syntax) – jsbillings May 29 '20 at 11:54
  • Again, @jsbillings I sound completely useless at this! - How could I add it on startup? - what line would I need to add to /etc/fstab? - What I was going to do is use the command mate-session-properties and add it to startup on there? - also how can I sort the mount to desktop/documents etc. thing out? - if you know what I should use - please could you specify the exact line of code that could solve both problems (startup and mount to user directories) - Thanks – ekv_56 May 29 '20 at 13:52
  • I updated the answer with the fstab entry. – jsbillings May 29 '20 at 15:53
  • Thanks for your reply, that will come in useful but how can I get it to mount on startup like you mentioned (exact line of code if you know) and why it won't mount to desktop/docs etc. - Thanks – ekv_56 May 29 '20 at 15:53
  • The addition you have made to the post worked well - thanks so much for that, that's sorted a security problem - but do you know anything about the questions in my comment earlier and I'll add them to the question too. – ekv_56 May 29 '20 at 16:01
  • Question updated with subquestions below the question. – ekv_56 May 29 '20 at 16:05
  • I've managed to get it to run on startup! - Finally! - Anyway - do you know why it wouldn't let me mount to a user directory like /home/username/Desktop or /home/username/Documents? Thanks – ekv_56 May 29 '20 at 18:49
  • It probably would be better to mount it to a central location and create symlinks in your homedir to Desktop and Documents. – jsbillings May 29 '20 at 20:49
  • Thanks for all your help @jsbillings – ekv_56 May 30 '20 at 09:01
  • I've hit a bump in the road - all was going well then I have come across a permissions problem - before I've been using root to test this out, but actually I need it to be mounted for a standard user. I have a script that I've set to run on startup with mate-session-properties which works for root, the script it just a plain executable .txt file with the command inside, but could I run it as root from that txt. script doc? - I'll explain more in the bottom of my question for you @jsbillings - please could you get back to me. Thanks – ekv_56 May 30 '20 at 11:19
  • See updated question with urgent subquestions - thanks so much – ekv_56 May 30 '20 at 11:34
  • Don’t mount it in a script. Put it in the fstab like in my answer. You’ll want to have the uid= and gid= parts refer to your user’s UID and GID. (See the output of id -u and id -g) – jsbillings May 30 '20 at 22:15
  • I seem to remember this not working when I tried it but I will exactly copy and paste your code into my /etc/fstab/ file and change the info I need to and let you know the outcome. Thanks. – ekv_56 May 31 '20 at 07:04
  • It says the mount option _netfs is not recognised. - Can you help? – ekv_56 Jun 02 '20 at 08:16
  • Why is _netfs not recognised - I really need to sort this thanks :) @jsbillings – ekv_56 Jun 03 '20 at 12:55
  • HI @jsbillings - the command _netfs is not being recognised - if you don't know why and can't sort it, do you know how to run su in a script? Thanks – ekv_56 Jun 03 '20 at 17:03
  • Sorry try _netdev instead. Got it mixed up in my head. – jsbillings Jun 04 '20 at 16:01
  • No problem at all - I'll have a go :) – ekv_56 Jun 04 '20 at 16:02
  • I get 'Unable to mount sharedfoldername, only root can mount sharedfoldername to sharedfoldermountlocation' – ekv_56 Jun 04 '20 at 16:13
  • Yes this is something that only root can do. But it should be set up to automatically mount on boot – jsbillings Jun 04 '20 at 16:23
  • No - I get an error message that flashes up really quickly on startup, saying something like 'cifs mount failure' – ekv_56 Jun 04 '20 at 16:27
  • Right - is there something I could edit the temporary mount command with (sudo mount -t cifs //ipaddress/sharedfoldername /mountlocation --verbose -o credentials=credentialsfilelocation) with to make it mount for a standard user but the sudo command executed by root because I could run that on startup. Also please see this question - I need your help! CLICK HERE FOR LINK – ekv_56 Jun 04 '20 at 16:32
  • You’d be better off getting the mount to work than writing a script to mount it. – jsbillings Jun 05 '20 at 00:03
  • Thanks - but because I'm quite inexperienced with this I'm not sure how to correct it. It just doesn't mount and I get the error I put on startup as well. I can try to confirm the error in a minute. Do you have any idea how to sort it? – ekv_56 Jun 05 '20 at 09:34
  • I'm going to do an fstab mount and work out why it's not working: LINK – ekv_56 Jun 08 '20 at 07:39