How to access share folder in virtualbox. Host Win7, Guest Fedora 16? - linux

I'm a newbie in linux. I installed Fedora 16 OS as guest in virtualbox on Window 7. Now, I want to access share folder from Fedora. Here is something I did:
Install guest addtion [OK]
Make share folder link to virtualbox [OK]. Share folder path in Window 7: D:\share_folder_vm
In terminal program in fedora, I just run some commands:
[hoangphi#localhost ~]$ su
Password:
[root#localhost hoangphi]# cd Desktop/
[root#localhost Desktop]# mkdir share_folder
[root#localhost Desktop]# sudo mount -t vboxsf D:\share_folder_vm \share_folder
/sbin/mount.vboxsf: mounting failed with the error: Protocol error
[root#localhost Desktop]#
I got this message: /sbin/mount.vboxsf: mounting failed with the error: Protocol error
share_folder_vm is the folder in Win7 Host and share_folder is the folder in Fedora Guest.
My question: How can I fix this problem?

Install Oracle Guest Additions:
[host-hotkey (usually right Ctrl)] + [d],
Then:
sudo /media/VBOXADDITIONS_4.*/VBoxLinuxAdditions.run
You can now enjoy:
A guest that can run at native screen resolution
Ability to share files between host and guest
Share the clipboard (allowing you to copy and paste between host and guest).
To share folders set them up to be shared. Consider the permissions. Note that the host file permissions are transient. IOW if you can't write to file on host, the guest can't either.
After setting up the file to be shared create a destination if you don't have one:
mkdir -p ~/destination
Now mount it under the name you configured it with:
sudo mount -t vboxsf myFileName ~/destination
As an extra tip you can really exploit this feature to do things like:
- Use guest subversion client to create repository to mounted directory (you won't have a full svn client but the repo can be used in an IDE on the host).
- I personally use my guest to download and unpack binaries like Tomcat to a targeted mount. Yes you can use Linux to install things on Windows!
To unmount all shares:
sudo umount -f -a -t vboxsf

This thread has some great tips. However....
#GirishB's answer isn't correct - sorry. Jartender's is best.
Also, every post in here seems to assume you're logging in to the Linux guest as root, except for #tomoguisuru. Yuck! Don't use root, use a separate user account and "sudo" when you need root privileges. Then this user (or any other user who needs the shared folder) should have membership in the vboxsf group, and #tomoguisuru's command is perfect, even terser than what I use.
Forget running mount yourself. Set up the shared folder to auto mount and you'll find the shared folder - it's under /media in my OEL (RH and Centos probably the same). If it's not there, just run "mount" with no arguments and look for the mounted directory of type vboxsf.

For accessing a shared folder, YOU have to have "Oracle VM extension pack" installed.
Look at the bottom of this link, you can download it from there.
http://www.oracle.com/technetwork/server-storage/virtualbox/downloads/index.html

I just figured. You need to add a shared folder using VirtualBox before you access it with the guest.
Click "Device" in the menu bar--->Shared File--->add a directory and name it
then in the guest terminal, use:
sudo mount -t vboxsf myFileName ~/destination
Dont directly refer to the host directory

There's a simpler way I found when running Linux Mint.
Ensure you install the Guest Additions from the command line and that you have the folder(s) shared with "automount" and "make permanent" settings selected within "Shared Folders" tab of the Machine Settings
Launch the User management application from Application/Settings/System Setting/ menu selection (requires sudo) from within the Mint menu
In the "Privileges and Groups" tab, check the box next to the "vboxsf" group, and then apply and ok your way back out.
Any user within the vboxsf group has full access to any shared folders on each boot with no manual mounting or unmounting
I usually do the following in addition to the above just to have quick access
Open the Dolphin file manager and navigate to /media/
Right-Click on the shared folder and click "Add to Places"

You probably need to change your mount command from:
[root#localhost Desktop]# sudo mount -t vboxsf D:\share_folder_vm \share_folder
to:
[root#localhost Desktop]# sudo mount -t vboxsf share_name \share_folder
where share_name is the "Name" of the share in the VirtualBox -> Shared Folders -> Folder List list box. The argument you have ("D:\share_folder_vm") is the "Path" of the share on the host, not the "Name".

May be this can help other guys:
I had the same problem, and after looking with Google I found that can be because of the permissions of the folder... So, you need first to add permissions...
$ chmod 777 share_folder
Then run again
$ sudo mount -t vboxsf D:\share_folder_vm \share_folder
Check the answers here: Error mounting VirtualBox shared folders in an Ubuntu guest...

VirtualBox version has many uncompatibilities with Linux version, so it's hard to install by using "Guest Addition CD image". For linux distributions it's frequently have a good companion Guest Addition package(equivalent functions to the CD image) which can be installed by:
sudo apt-get install virtualbox-guest-dkms
After that, on the window menu of the Guest, go to Devices->Shared Folders Settings->Shared Folders and add a host window folder to Machine Folders(Mark Auto-mount option) then you can see the shared folder in the Files of Guest Linux.

There is a really simple tuturial here : http://my-wd-local.wikidot.com/otherapp:configure-virtualbox-shared-folders-in-a-windows-ho
telling to do:
sudo mkdir /mnt/vbox_share
sudo mount.vboxsf nameAddesAsShared /mnt/vbox_share

These are the steps to share a folder from Windows to Linux Virtual Box
Step 1 : Install Virtual Box Extension Pack from this link
Step 2: Install Oracle Guest Additions:
By pressing -> Right Ctrl and d together
Run the command
sudo /media/VBOXADDITIONS_4.*/VBoxLinuxAdditions.run
Step 3 : Create Shared Folder by Clicking Settings in Vbox
Then Shared Folders -> + and give a name to the folder (e.g. VB_Share)
Select the Shared Folder path on Windows (e.g. D:\VBox_Share)
Step 4: Create a folder in named VB_share in home\user-name (e.g. home\satish\VB_share) and share
mkdir VB_Share
chmod 777 VB_share
Step 5: Run the following command
sudo mount –t vboxsf vBox_Share VB_Share

Related

How to run SUDO command in WinSCP to transfer files from Windows to linux [duplicate]

This question already has answers here:
WinSCP connect to Amazon AMI EC2 Instance changing user after login to "root"
(6 answers)
Closed last year.
I am trying to use WinSCP to transfer files over to a Linux Instance from Windows.
I'm using private key for my instance to login to Amazon instance using ec2-user. However ec2-user does not have access to write to the Linux instance
How do I sudo su - to access the root directory and write to the Linux box, using WinSCP or any other file transfer method?
Thanks
I know this is old, but it is actually very possible.
Go to your WinSCP profile (Session > Sites > Site Manager)
Click on Edit > Advanced... > Environment > SFTP
Insert sudo su -c /usr/lib/sftp-server in "SFTP Server" (note this path might be different in your system)
Save and connect
Source
AWS Ubuntu 18.04:
There is an option in WinSCP that does exactly what you are looking for:
AFAIK you can't do that.
What I did at my place of work, is transfer the files to your home (~) folder (or really any folder that you have full permissions in, i.e chmod 777 or variants) via WinSCP, and then SSH to to your linux machine and sudo from there to your destination folder.
Another solution would be to change permissions of the directories you are planning on uploading the files to, so your user (which is without sudo privileges) could write to those dirs.
I would also read about WinSCP Remote Commands for further detail.
Usually all users will have write access to /tmp.
Place the file to /tmp and then login to putty , then you can sudo and copy the file.
I just wanted to mention for SUSE Enterprise server V15.2 on an EC2 Instance the command to add to winSCP SFTP server commands is :
sudo su -c /usr/lib/ssh/sftp-server
I didn't have enough Reputation points to add a comment to the original answer but I had to fish this out so I wanted to add it.
ssh to FreePBX and run the commands stated below in your terminal:
sudo nano -f /etc/sudoers.d/my_config_file
YourUserName ALL=(ALL) NOPASSWD:ALL
sudo systemctl restart sshd
Winscp:
under session login ==> Advanced ==> SFTP
Change SFTP Server to:
sudo /usr/libexec/openssh/sftp-server
I do have the same issue, and I am not sure whether it is possible or not,
tried the above solutions are not worked for me.
for a workaround, I am going with moving the files to my HOME directory, editing and replacing the files with SSH.
Tagging this answer which helped me, might not answer the actual question
If you are using password instead of private key, please refer to this answer for tested working solution on Ubuntu 16.04.5 and 20.04.1
https://stackoverflow.com/a/65466397/2457076

mount remote windows share from centos

I am trying to setup a script that will:
Connect to a windows share
Using LOAD DATA LOCAL INFILE, upload the two files into their appropriate db tables
Umount share
Situation:
I can currently vpnc into this remote machine
Problem:
I cannot
mount -t cifs //ip.address/share /mnt/point -o username=u,password=p,port=445
mount error(110) Connection timed out
I am attempting to do this manually first
Remote server is open to port 445
Questions:
Do I even need to vpnc in first?
Do I need to do route add for the remote ip/mask/gw after vpnc?
Thank you!
The mount.cifs file is provided by the samba-client package. This can be installed from the standard CentOS yum repository by running the following command:
yum install samba samba-client cifs-utils
Once installed, you can mount a Windows SMB share on your CentOS server by running the following command:
Syntax:
mount.cifs //SERVER_ADDRESS/SHARE_NAME MOUNT_POINT -o user=USERNAME
SERVER_ADDRESS: Windows system’s IP address or hostname
SHARE_NAME: The name of the shared folder configured on the Windows system
USERNAME: Windows user that has access to this share
MOUNT_POINT: The local mount point on your CentOS server
I am mounting to a share from \\10.11.10.26\snaps
Make a directory under mount for your reference
mkdir /mnt/mymount
Now I am mounting the snaps folder from indiafps02, User name is the Domain credentials, i.e. Mydomain in this case
mount.cifs //10.11.10.26/snaps /mnt/mymount -o user=Girish.KG
Now you could see the content by typing
ls /mnt/mymount
So, after performing your task, just fire umount command
umount /mnt/mymount
That's it. You are done.
no need to install "samba" and "samba-client", only "cifs-utils" using command
yum install cifs-utils
after that in windows share the folder you would like to mount in centos if you didn't do that already ("c:\interpub\wwwroot" in my case).
make sure you share it with a specific username whom your know the password for ("netops" in my case).
create a directory in centos in which you would like to mount the windows share in to ("/mnt/cm" in my case).
after that run that simple command as a root
mount.cifs //10.16.0.160/wwwroot /mnt/cm/ -o user=netops
centos will prompt you for the windows username password.
you are done.

creating symbolic link: Protocol error

I have created linux (Centos) on my virtual box. When I ssh to it and I try to create symbolic link (on my shared folder with full access):
ln -s path/folder/example myFolder
I get error:
ln: creating symbolic link `myFolder': Protocol error
Is there any reason or solution to this?
Right click on your command prompt and "Run as Administrator" (or whatever program you're using to make those symlinks needs to be run as adminstrator).
Here is the solution in a ticket on virtualbox.org :
https://www.virtualbox.org/ticket/10085#comment:32
(Note: Execute "whoami /priv" in console with Administrative privileges)
I have done some Windows research on this bug.
If your user is of the Administrator type (rather than a Standard
account), there's no way to run VB with symlinks working without the
UAC prompt.
If you have a Standard user account (or if you are willing to switch
your account to Standard and create a separate Admin account), the
solution exists. You will, however, need admin privileges to
accomplish several of the steps (not necesarrily for your user
account).
Run the Local Security Policy (Win+R, type "secpol.msc", confirm UAC). Then navigate to "Local Policies->User Rights Assignment".
Find the permission called "Create symbolic links" and double-click it. Add your user to the list of objects having this
permission. Or you can add the "Users" group. Log off and log on. You
can check the success by running in console:
whoami /priv
If you see the privilege SeCreateSymbolicLinkPrivilege enabled, you've
done well.
Make sure your user has proper access to the shared folder on host system.
As mentioned here earlier, execute
VBoxManage setextradata VM_NAME VBoxInternal2/SharedFoldersEnableSymlinksCreate/SHARE_NAME 1
in a console from the C:\Program Files\VirtualBox folder. Don't forget
to substitute VM_NAME with the name of your VM and SHARE_NAME with the
name of the shared folder (as it appears in the VM settings).
You're done.
If you happen to own one of the "lesser" version of windows (e.g. 7
Home), you don't have the "secpol.msc" utility. See
How do I grant SeCreateSymbolicLink on Windows Vista Home edition
for help.
It's a problem with the host filesystem. Check the permissions on the host folder are adequate and the the host filesystem supports symlinks.
As I understand, Windows VirtualBox hosts doesn't support links (from https://www.virtualbox.org/manual/ch04.html#sharedfolders)
Starting with version 4.0, VirtualBox shared folders also support
symbolic links (symlinks), under the following conditions:
The host operating system must support symlinks (i.e. a Mac, Linux or
Solaris host is required).
Currently only Linux and Solaris Guest Additions support symlinks.
For security reasons the guest OS is not allowed to create symlinks by
default. If you trust the guest OS to not abuse the functionality, you
can enable creation of symlinks for "sharename" with:
VBoxManage setextradata "VM name"
VBoxInternal2/SharedFoldersEnableSymlinksCreate/sharename 1
find the cmd.exe file.
Right click on the cmd.exe .
Select "Run as Administrator" menu option.
It should work perfectly.
By default VirtualBox VM disables creation of symbolic links.
Oracle VM VirtualBox shared folders support symbolic links under the following conditions:
The host operating system must support symlinks. For example, a Mac OS X, Linux, or Oracle Solaris host is required.
Currently only Linux and Oracle Solaris Guest Additions support symlinks.
For security reasons the guest OS is not allowed to create symlinks by default.
To enable creation of symlinks for a shared folder you should do:
Run this command on your host (where {VM_name} is the name of VM and {share_folder_name} is the name of shared directory):
$ VBoxManage setextradata "{VM_name}" VBoxInternal2/SharedFoldersEnableSymlinksCreate/{share_folder_name} 1
In my case it looks like:
$ VBoxManage setextradata "ubuntu16" VBoxInternal2/SharedFoldersEnableSymlinksCreate/shared 1
Reboot the VM.
More information you can find here:
https://docs.oracle.com/cd/E97728_01/E97727/html/sharedfolders.html
https://www.virtualbox.org/ticket/18572?cversion=0&cnum_hist=2
Basically you need to again tell VirtualBox to enable symlinks. Here's the complete solution
Have this in your vagrant file,
config.vm.provider "virtualbox" do |v|
v.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/Folder_Name", "1"]
end
I recommended comment out any sync folder and let default ./(at host) synced at /vagrant(at guest). This will make sure your shared folder(Folder_Name) name is always vagrant as mentioned here https://www.vagrantup.com/docs/synced-folders/. Also, you won't face issues with ssh
If the symlink protocol error returns after restart or still persists run
VBoxManage setextradata "VM_Name" VBoxInternal2/SharedFoldersEnableSymlinksCreate/Folder_Name 1
vagrant halt
vagrant up
vagrant ssh
Usually, VBoxManagee is located at C:\Program Files\Oracle\VirtualBox\
Verify working of symlink by going to /vagrant and running
touch test.txt && ln -s test.txt test1.txt
PS: I have tried this on Windows Home which has limited accessibility to security settings
I observed the same error in virtual box ( Lubuntu running in Windows 10). Issue got resolved by running "Oracle VM Virtualbox" using 'Run As Administrator' option.
I solved this issue by changing the local security policy in my windows. Search for local security policy and open it then on the left-hand side select Local Policies -> User Rights Assignments -> Create Symbolic Links
Click on Add User or Group
Type in everyone in the select user/group prompt.
Reboot your system
It should work.

XAMPP or any other service tool in /opt? Security

I am developing with Xampp for Linux and Tomcat (similar to Xampp on Windows). Many programs like /IDEA, Tomcat and Xampp are recommended to be installed under /opt Now I have heard that it is not recommended to run services as root, but on Ubuntu (I am using this) unpacking any directory to /opt implies that it belongs to root owner and root group. This may be specific to Xampp as per the instructions on their Linux page:
Step 2: Installation After downloading simply type in the following commands:
Go to a Linux shell and login as the system administrator root:
su
Extract the downloaded archive file to /opt:
tar xvfz xampp-linux-1.8.1.tar.gz -C /opt
Warning: Please use only this command to install XAMPP. DON'T use any Microsoft Windows tools to extract the archive, it won't work.
Warning 2: already installed XAMPP versions get overwritten by this command.
That's all. XAMPP is now installed below the /opt/lampp directory.
* Step 3: Start To start XAMPP simply call this command:
/opt/lampp/lampp start
Placing it here implies that Apache must be run as root as one is only able to run it with sudo on Ubuntu.
This may be an issue specific to Ubuntu. Is it? Because Xampp is a development tool I posted this here as I am more likely to find an appropriate answer here from developers who use it on Ubuntu (and other Linux systems). I would appreciate any information on if the same problem occurs on other systems, I notice my production environment has Tomcat installed in /opt too, but belongs to tomcat: tomcat
The question here is how to get around this for all tools under /opt, because even though Xampp may not be the tool for my needs, I still want to place Tomcat under /opt to replicate my production environment and the same thing will surely happen unless this is just a Ubuntu issue?
Ubuntu and some other distributions differ to the general Linux principle where the account that you create upon install of the OS is added to specific groups that can be viewed with the following command:
groups username
You will notice that root is not amongst these. It is also not possible to log in or su to the root account. sudo is most likey a command that has been granted permission to be used from other accounts so I imagine the 'sudo' command has a file permission of 775 for user: root:root
Thus launching services from /opt' does not run them asroot`

Install chromium to Linux disk image?

I'm sure this has been asked before but I have no clue what to search for
I am trying to create a custom Linux image (for the Raspberry Pi) - I am currently manipulating the filesystem of the .img but I've discovered it's not as simple as dropping in the binary :( if only...
What is the accepted way to "pre-install" a package on a disk image where you can only manipulate the filesystem and ideally not run it first? Am I best to boot up, install, and then create the image from that, or is there a way of doing it beforehand in the same way you can change configuration settings etc?
Usually, when I have to change something in a disk image, I do the following:
sudo mount --bind /proc /mnt/disk_image/proc
sudo mount --bind /sys /mnt/disk_image/sys
sudo mount --bind /dev /mnt/disk_image/dev
These action are needed as this folder are create during boot process, mounting them in your system image will emulate a full boot. Then, you can chroot on it safely:
sudo chroot /mnt/disk_image
You're now able to issue commands in the chroot environment:
sudo apt-get install chromium
Of course, change /mnt/disk_image to the path where you have mounted your filesystem. apt-get will only works on Debian based system, change it according to your distribution.
You could find problem connecting to the internet and it can be cause by DNS configuration. The best thing you can do, is to copy your /etc/resolv.conf file in the remote filesystem as this file is usually changed by dhcp and it's empty on chroot environment.
This is the only solution that gives you full access to the command line of the system you're trying to modify.
This is an untested idea:
The dpkg tool, which can install .deb packages, has a --root option which can set a different filesystem than the local / path.
From the man page:
--instdir=dir
Change default installation directory which refers to the
directory where packages are to be installed. instdir is
also the directory passed to chroot(2) before running
package’s installation scripts, which means that the
scripts see instdir as a root directory. (Defaults to /)
--root=dir
Changing root changes instdir to dir and admindir to
dir/var/lib/dpkg.
If you mount your image and pass its mountpoint as --root, it should work.
There are things like the Ubuntu Customization Kit which allow you to create your own version of the distro with your own packages.
Crunchbang even has a utility like this, which is the distro I have personally selected for experimenting with my Pi.

Resources