Tuesday, December 1, 2020

Mount linux partition to windows

 

Local Windows access remote Linux with samba


在linux服务器上配置samba,有两种方式:share方式,user方式。

1. share方式:也就是访问共享文件夹时不需要输入共享文件夹的密码,所有guest都能访问。这种不需要密码的访问当然不安全,但是很方便,也是比较常用的方式。配置步骤如下:

(1) Install samba
sudo apt-get install samba
(2)配置samba
sudo vi /etc/samba/smb.conf
打开这个文件后,按如下添加信息:
[share]
comment = yangxxxx samba share dir
path = /home/wxxhxx/share
browseable = yes
guest ok = yes
create mask = 0777
writable = yes
在这里插入图片描述
注意:这里的写权限单词不要拼写错了writable。
注意:samba版本,我是samba4.7,其中已经没有security = share这种写法了,有的网上资料里都会配置这个参数,这是以前的写法,samba4里面用的是map to guest = Bad User。
保存配置。
(3)重启samba服务:sudo /etc/init.d/smbd restart
(4) windows下访问:
win+r打开这面运行框,输入linux的ip地址后点确定。
在这里插入图片描述
可以看到linux下创建的share共享文件夹,因为我开通了所有权限,所以在这里啥都可以干,新建、修改、删除文件都可以。
在这里插入图片描述


2.user方式:也就是指定的user才有权访问共享文件夹。配置步骤如下:

(1)首先要创建samba user
sudo useradd yangxxsmb (这个名字自定义)
sudo smbpasswd -a yangxxsmb (给这个用户设置访问密码,自定义一个密码,系统会要求输入两边密码,密码自己要记好不然访问不了共享文件夹了。)
(2)samba配置
sudo vi /etc/samba/smb.conf
打开文件,按如下配置,没有的就手动添加。
[share]
comment = yangxxxx samba share dir
path = /home/wxxhxx/share
browseable = yes
writable = yes
valid users = yangxxsmb

(3)重启samba服务
sudo /etc/init.d/smbd restart
(4) windows访问共享文件夹
win+r打开这面运行框,输入linux的ip地址后点确定。
在这里插入图片描述
可以看到share文件夹,但是要访问时需要输入用户名和密码,就是步骤(2)中设置的用户名和密码,输入之后就可以访问了,也可以在里面新建、修改、删除文件。
在这里插入图片描述

Fix docker: Got permission denied while trying to connect to the Docker daemon socket

 According to the official Docker docs here:

https://docs.docker.com/install/linux/linux-postinstall/#manage-docker-as-a-non-root-user

You need to do the following:

To create the docker group and add your user:

  • Create the docker group.
sudo groupadd docker
  • Add your user to the docker group.
sudo usermod -aG docker ${USER}
  • You would need to loog out and log back in so that your group membership is re-evaluated or type the following command:
su -s ${USER}
  • Verify that you can run docker commands without sudo.
docker run hello-world
  • This command downloads a test image and runs it in a container. When the container runs, it prints an informational message and exits.

  • If you initially ran Docker CLI commands using sudo before adding your user to the docker group, you may see the following error, which indicates that your ~/.docker/ directory was created with incorrect permissions due to the sudo commands.

WARNING: Error loading config file: /home/user/.docker/config.json -
stat /home/user/.docker/config.json: permission denied
  • To fix this problem, either remove the ~/.docker/ directory (it is recreated automatically, but any custom settings are lost), or change its ownership and permissions using the following commands:
sudo chown "$USER":"$USER" /home/"$USER"/.docker -R
sudo chmod g+rwx "$HOME/.docker" -R