可能在日常中经常使用到虚拟机做开发,但宿主机和虚拟机之间拷贝文件之类的操作太麻烦,其实我们可以安装samba并将home目录做共享,方便操作。
系统环境:ubuntu20.04 LTS
安装samba
sudo apt install samba samba-common
配置文件
sudo /etc/samba/smb.conf
samba 本身的配置已经有共享用户目录的配置,只需要将前面的注释符号去掉即可使用。
搜索homes即可找到对应的配置,将其改成以下的例子, 如果没有找到homes这个区块,也可以自己添加以下代码在配置文件的最后。
[homes]
; comment = Home Directories
browseable = yes
# By default, the home directories are exported read-only. Change the
# next parameter to 'no' if you want to be able to write to them.
read only = no
# File creation mask is set to 0700 for security reasons. If you want to
# create files with group=rw permissions, set next parameter to 0775.
create mask = 0755
# Directory creation mask is set to 0700 for security reasons. If you want to
# create dirs. with group=rw permissions, set next parameter to 0775.
directory mask = 0755
# By default, \\server\username shares can be connected to by anyone
# with access to the samba server.
# Un-comment the following parameter to make sure that only "username"
# can connect to \\server\username
# This might need tweaking when using external authentication schemes
valid users = %S
保存后重启samba服务
sudo service smbd restart
添加samba用户密码
sudo smbdpasswd -a xxx
xxx为你的登陆用户名(同时也是ubuntu系统登陆的用户名)
然后会让输入两次密码
之后即可以在windows主机上通过共享的方式打开linux系统上的用户home目录。
\\ip\xxx
xxx为用户名
如果windows提示没有操作权限
windows上需要安装SMB 1.0/CIFS 文件共享支持
在windows功能里面选择安装即可