How do I use a Samba server location for GOPATH? - linux

I am trying to set my GOPATH to a shared network folder. When I enter
export GOPATH=smb://path/to/shared/folder
I get:
go: GOPATH entry is relative; must be absolute path: "smb".
Run 'go help gopath' for usage.
I've also tried to prefix the path w/ "/" but then it tries to make a folder in root.
thx!

there is only one solution for this:
Map ( mount) a Samba server file path as a Local Disk Drive ( local path),
then set GOPATH to this local path:
Mounting SMB share on local folder by using smbmount command (smbmount is deprecated):
smbmount //ipadd/sharename /mountpoint –o username=userid,workgroup=workgroupname
Example :
smbmount //192.168.0.1/share1 /mnt –o username=steev,workgroup=test
Mounting SMB share by using mount command
mount –t smbfs ipadd:/sharename /mountpoint –o username=userid,workgroup=workgroupname
Or
mount –t smbfs //ipadd/sharename /mountpoint –o username=userid,workgroup=workgroupname
Example :
mount –t smbfs 192.168.0.1:/share1 /mnt –o username=surendra,workgroup=test
ref:
http://www.linuxnix.com/8-ways-to-mount-smbfs-samba-file-system-in-linux/
https://askubuntu.com/questions/232998/how-do-i-install-smbmount
http://www.howtogeek.com/116309/use-ubuntus-public-folder-to-easily-share-files-between-computers/
and for Windows: https://serverfault.com/questions/6079/how-can-i-mount-an-ftp-to-a-drive-letter-in-windows

You need to mount the Samba share to a folder on your machine:
$ mkdir /mnt/samba
$ smbmount smb://path/to/share /mnt/samba
Of course you may need to use switches on the smbmount command to provide username, password, workgroup, etc., depending on the configuration of the Samba share you're trying to access. Once you've mounted the share you can then do
$ export GOPATH=/mnt/samba
And as far as Go is concerned the files in the Samba share will be located on your local machine.

Related

Shell script to mount windows network location in linux machine

I have two questions here. I am able to mount a windows network path in my Ubuntu machine by doing following:
sudo mount -t cifs -o username=user \\\\my_windows\\test /net/loc
All the files and folders present in Windows machine is now available in Ubuntu machine with path '/net/loc'.
Here are my doubts:
I can see all files of windows in linux path. Is it possible to create files/folders in Linux path(the mount path where windows path is mounted) and it will be reflected in Windows machine? I am not able to write in Linux machine where windows network location is mounted. It throws me error "Can't open file for writing".
I am trying to write a shell script (a ksh file) which will mount the windows network path. I wrote the below mount command in my file but this command prompts for password. Is there any way, I can write the command in shell script that it will not ask me for password and I can pass it as either as a parameter or some other mechanism?
mount -t cifs -o username=user \\my_windows\test /net/loc
Thank you
Password can be passed as below
sudo mount -t cifs -o username=${USER},password=${PASSWORD},uid=,gid= //server-address/folder /mount/path/on/ubuntu
And with root access I am able to write in Linux path.
More information is here https://unix.stackexchange.com/questions/68079/mount-cifs-network-drive-write-permissions-and-chown

How to mount a directory for a user that doesn't exist yet in vagrant

I'm trying to mount a data disk in vagrant using the shared folder mechanism, which works well except that the directory is owned by vagrant by default and tomcat6 can't write to it. So I thought I could set the owner of the disk in the vagrantfile using:
config.vm.synced_folder "data/", "/data", owner: "tomcat6", group: "tomcat6"
but the tomcat6 user doesn't exist yet as the tomcat recipe hasn't been run yet so vagrant fails with:
Failed to mount folders in Linux guest. This is usually because
the "vboxsf" file system is not available. Please verify that
the guest additions are properly installed in the guest and
can work properly. The command attempted was:
mount -t vboxsf -o uid=`id -u tomcat6`,gid=`getent group tomcat6 | cut -d: -f3` data /data
mount -t vboxsf -o uid=`id -u tomcat6`,gid=`id -g tomcat6` data /data
The error output from the last command was:
stdin: is not a tty
id: tomcat6: no such user
id: tomcat6: no such user
uid= requires an argument (i.e. uid==<arg>)
Now I can work round this by mounting /data with world write permission but that seems "wrong" to me (even on a test machine).
So is there any way to make vagrant create a new user for me before I mount the disk or to have Chef provision me a shared disk later?
You could switch to the nfs sync provider as that supports remote files with unknown UIDs. See https://docs.vagrantup.com/v2/synced-folders/nfs.html for details.
A workaround I've used for my own VMs has been to force Vagrant to re-run the initial setup after running provisioning:
vagrant up # this fails at synced_folder; put that at the end of Vagrantfile
vagrant provision # this creates the user
vagrant halt # shut down
vagrant up # re-runs the synced_folder command, this time the user exists
It's not graceful, but stick it in a bash script and it'll prop up a working VM.
If you know what the UID/GID of the future user will be, you can simply provide those values instead of the user/group names. e.g. if 'tomcat6' has GID/GID of 11111, you could state in your Vagrantfile:
config.vm.synced_folder "data/", "/data", owner: "11111", group: "11111"

Locked out of cifs mounted storage

I've been using this line in /etc/fstab for mounting a storage device to my host:
//url.to-my-storage.com/mystorage /mnt/backup cifs
iocharset=utf8,rw,credentials=/etc/backup-credentials.txt,uid=1000,gid=1000,file_mode=0660,dir_mode=0770
0 0
I was mounting it to another host, and I ran this to protect the files from change through the new host:
chmod -R 444 /mnt/backup
(I tried to protect the storage from writing from this host, which turned out to change the mode of all the storage files)
I assume the missing executable permissions what causing me this:
$ sudo mount -a
mount error(13): Permission denied
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)
I tried unmounting and mounting again, that didn't help, got the same permission error when using the mount command.
ls the dir shows this:
$ ls -la /mnt/backup
?????????? ? ? ? ? ? backup
HELP !
Dismounting a "Locked Out" Network Drive
To dismount a "locked out" network drive, you can try to force the unmount:
umount -f -t cifs /mnt/backup
If you are having trouble dismounting a drive, make sure that you don't have a console open somewhere where the current working directory (CWD) on the drive which you are trying to dismount, or have a file open in an editor or player somewhere or such.
Properly Mounting a Network Drive
You should add your permissions in your mount options rather than trying to apply them afterwards. You would want to replace these mount options:
rw,file_mode=0660,dir_mode=0770
with
ro
Currently you are mounting your CIFS drive as read-write (rw), giving files read-write permission (file_mode=0660) and directories read-write-execute (dir_mode=0770). Simply mounting the drive as read-only (ro) should suffice. (If you do need to fine tune the file and dir modes, rather use umask.)
I would also advise you to double check whether you are using uid and gid correctly: if the user ID or group ID used gets deleted, that could also lead to problems.
References
https://linux.die.net/man/8/mount
https://en.wikipedia.org/wiki/File_system_permissions
https://oracletechdba.blogspot.com/2017/06/umount-lsof-warning-cant-stat-cifs-file.html
https://stackoverflow.com/a/40527234/171993

Sshfs as regular user through fstab

I'd like to mount a remote directory through sshfs on my Debian machine, say at /work. So I added my user to fuse group and I run:
sshfs user#remote.machine.net:/remote/dir /work
and everything works fine. However it would be very nice to have the directory mounted on boot. So I tried the /etc/fstab entry given below:
sshfs#user#remote.machine.net:/remote/dir /work fuse user,_netdev,reconnect,uid=1000,gid=1000,idmap=user 0 0
sshfs asks for password and mounts almost correctly. Almost because my regular user has no access to the mounted directory and when I run ls -la /, I get:
d????????? ? ? ? ? ? work
How can I get it with right permissions trough fstab?
Using option allow_other in /etc/fstab allows other users than the one doing the actual mounting to access the mounted filesystem. When you booting your system and mounting your sshfs, it's done by user root instead of your regular user. When you add allow_other other users than root can access to mount point. File permissions under the mount point still stay the same as they used to be, so if you have a directory with 0700 mask there, it's not accessible by anyone else but root and the owner.
So, instead of
sshfs#user#remote.machine.net:/remote/dir /work fuse user,_netdev,reconnect,uid=1000,gid=1000,idmap=user 0 0
use
sshfs#user#remote.machine.net:/remote/dir /work fuse user,_netdev,reconnect,uid=1000,gid=1000,idmap=user,allow_other 0 0
This did the trick for me at least. I did not test this by booting the system, but instead just issued the mount command as root, then tried to access the mounted sshfs as a regular user.
Also to complement previous answer:
You should prefer the [user]#[host] syntax over the sshfs#[user]#[host] one.
Make sure you allow non-root users to specify the allow_other mount option in /etc/fuse.conf
Make sure you use each sshfs mount at least once manually while root so the host's signature is added to the .ssh/known_hosts file.
$ sudo sshfs [user]#[host]:[remote_path] [local_path] -o allow_other,IdentityFile=[path_to_id_rsa]
REF: https://wiki.archlinux.org/index.php/SSHFS
Also, complementing the accepted answer: there is a need that the user on the target has a right to shell, on target machine: sudo chsh username -> /bin/bash.
I had a user who had /bin/false, and this caused problems.

How to rename a MOUNT (mounted shared folder from Windows named mnt)

How to rename a MOUNT (mounted shared folder from Windows named mnt)?
How to rename mnt?
This is the command I used on linux command tool to mount my Shared folder from windows pc to a linux controller.
# mount -t cifs -o username=myusername,password=mypassword //10.80.50.50/Share /mnt
So my mounted Shared folder is now name mnt... How to rename it?
Thanks...
Follow these steps:
Unmount:
umount /mnt
Create another folder:
mkdir /my_new_mount
Mount again:
mount -t cifs -o username=myusername,password=mypassword //10.80.50.50/Share /my_new_mount
Update in /etc/fstab

Resources