Ubuntu 20.04.1安装Samba服务器及配置 1查看Ubuntu的版本 agold@ubuntu:~$ cat /etc/issue ![](https://s4.51cto.com/images/blog/202012/21/b2d0c01fa71d04f1746e147971233f9c.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=) 2更新软件 agold@ubuntu:~$ sudo apt-get upgrade ![](https://s4.51cto.com/images/blog/202012/21/eaf9b4306a359fe66651e691af0d5975.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=) 3查看samba的安装情况 sudo dpkg -l | grep samba ![](https://s4.51cto.com/images/blog/202012/21/6a484693c41af48b0e7ffce24794704b.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=) 4 安装samba agold@ubuntu:~$ sudo apt-get install samba samba-common 输入Y ![](https://s4.51cto.com/images/blog/202012/21/2f2732a227631ffab5881621a38d48fb.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=) 5 在/home/创建文件夹A和shared agold@ubuntu:/home$ sudo mkdir A agold@ubuntu:/home$ sudo mkdir shared ![](https://s4.51cto.com/images/blog/202012/21/f05a7ea376977c17d11cd9385e4c4d00.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=) 6 更改文件夹A和shared权限为777(任意用户可读可写可执行) agold@ubuntu:/home$ sudo chmod 777 A agold@ubuntu:/home$ sudo chmod 777 shared ![](https://s4.51cto.com/images/blog/202012/21/818f68a9abe6e3c164a6770be033033f.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=) 7 增加两个账户wjy,syj agold@ubuntu:/home$ sudo useradd wjy agold@ubuntu:/home$ sudo useradd syj ![](https://s4.51cto.com/images/blog/202012/21/34462a0b00252bb33c53a395cf51d71c.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=) 8 为wjy,和syj创建samba密码 agold@ubuntu:/home$ sudo smbpasswd -a wjy agold@ubuntu:/home$ sudo smbpasswd -a syj ![](https://s4.51cto.com/images/blog/202012/21/33d451f51f32891a22b2b107890c4f46.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=) 9如果ifconfig不能用请安装net-tools agold@ubuntu:/home$ sudo apt install net-tools ![](https://s4.51cto.com/images/blog/202012/21/4fb80d1389ea9fb95429c7b791c72ab4.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=) 再次查看 ![](https://s4.51cto.com/images/blog/202012/21/4dba981ec5b403a1c545fb17aad9c67f.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=) 10更改/etc/samba/smb.conf 可以复制粘贴,agold@ubuntu:/home$ sudo gedit /etc/samba/smb.conf [global] workgroup = WorkGroup security = user passdb backend = tdbsam map to guest = bad user [公共文件] comment = 公共文件 browseable=yes path = /home/A guest ok = yes [个人] comment = 个人 path = /home/shared browseable=yes create mask=0644 directory mask=0755 valid users=wjy write list=wjy [组] comment =组 path = /home/shared browseable=yes create mask=0644 directory mask=0755 valid users=syj,wjy write list=syj,wjy 11启动samba agold@ubuntu:~$ sudo service smbd restart ![](https://s4.51cto.com/images/blog/202012/21/f60570ba740a82bf47cd9cccc5ae15e8.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=) 12打开Windows 10客户端 ![](https://s4.51cto.com/images/blog/202012/21/16c1b1dbdc2dbab78608c8a47d7a94f8.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=) ![](https://s4.51cto.com/images/blog/202012/21/d70c8bf82d51e9397015d5f387b82ae2.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=) 13 可以浏览到共享文件夹,公共文件可以直接访问 ![](https://s4.51cto.com/images/blog/202012/21/afc0a810a5666d867b2bffdb11738fd9.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=) ![](https://s4.51cto.com/images/blog/202012/21/1873540eb66d6cd40e7f98698daf192a.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=) 14 试图往里面复制文件 没有权限 ![](https://s4.51cto.com/images/blog/202012/21/b9dd572f983f6e74cb8f6abc2b6f0d84.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=) 15点击个人则需要账户和密码,输入上面设置的账户和密码, ![](https://s4.51cto.com/images/blog/202012/21/1961fab9096ad8e396ac0e50ff173625.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=) 可以正常登陆 ![](https://s4.51cto.com/images/blog/202012/21/b34c4ba9d4020f621010bca18b60f3b5.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=) 我们往里面复制文件,可以复制有读写权限 ![](https://s4.51cto.com/images/blog/202012/21/d3e06a71dc01b3e6bd397ef4df02edb4.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=) 16,我们点开组文件夹发现没有让我输入账户密码,因为组权限里面包含这个账户,并且账户在缓存里记住。 ![](https://s4.51cto.com/images/blog/202012/21/38ad85a3c1092f54a5b7c2dde4e165e1.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=) 17 那我们如何切换账户那,记事本写个bat内容如下,之后保持文1.bat 名字随意。之后运行它 net use * /del -y net stop workstation net start workstation ![](https://s4.51cto.com/images/blog/202012/21/dd59fe44a1cfde5db86be80373191d9a.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=) ![](https://s4.51cto.com/images/blog/202012/21/dde4c4352108c3151929f5da11b5dddb.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=) 18 我们再次打开共享,会发现需要重新输入账户和密码,我们可以切换一下账户。 ![](https://s4.51cto.com/images/blog/202012/21/50ecb955a1fde3b642a657a5c22e53b7.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=) ![](https://s4.51cto.com/images/blog/202012/21/72ce8bc41fc5230423edd420d3281fc7.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=) 可以登录,同时我们复制一个搜狗五笔输入法进去,可以看到有复制权限。 ![](https://s4.51cto.com/images/blog/202012/21/008b15849bd64e0e26c554056515ea7d.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)