背景
samba服務+vscode 實現代碼快速修改生效到服務器上
最終實現,開發的編輯器與遠程的linux目錄下的代碼聯動起來,實現本地修改與遠程代碼同步。
step1
linux服務上安裝samba服務,實現遠程linux服務機器與本地機器文件共享。(備注:該教程在linux上使用的root用戶)
centos系統
- yum install -y samba
- vi /etc/samba/smb.conf
-
-
# See smb.conf.example for a more detailed config file or # read the smb.conf manpage. # Run 'testparm' to verify the config is correct after # you modified it. [global] workgroup = SAMBA security = user passdb backend = tdbsam printing = cups printcap name = cups load printers = yes cups options = raw [homes] comment = Home Directories valid users = %S, %D%w%S browseable = No read only = No inherit acls = Yes [printers] comment = All Printers path = /var/tmp printable = Yes create mask = 0600 browseable = No [print$] comment = Printer Drivers path = /var/lib/samba/drivers write list = @printadmin root force group = @printadmin create mask = 0664 directory mask = 0775 ### 以下為新增 ### [root] comment = user root share files # 隨意寫,描述用途 path = /root # 共享linux的目錄 writable = yes #將linux共享的目錄實現可寫操作 public = no
- 將root用戶添加到samba的服務中
- smbpasswd -a root (添加過程中要輸入密碼,記住該密碼,遠程登陸的時候需要)
- 重啟samba服務:systemctl restart smb
-
ubuntu系統
- 安裝samba: sudo apt-get install samba samba-common
- 配置smb.conf : vi /etc/samba/smb.conf 在該文件中追加如下代碼
[share] comment = share folder browseable = yes path = /root # 要共享的目錄 create mask = 0700 directory mask = 0700 valid users = root force user = root force group = root public = yes available = yes writable = yes
3. smb添加用戶: smbpasswd -a root
4. 重啟smb服務: service smbd restart
step2 本地windows電腦上的操作
1. 網絡連接遠程機器的ip,如下圖所示
2. 輸入smbpasswd -a root 操作過程中輸入的密碼
3. 本地通過網路,成功進入遠程linux share的文件目錄
step3 vscode 打開本地的網絡共享的文件目錄root
1. 網絡文件夾驅動映射到本地
2. vscode打開映射到本地的網絡T文件夾,即實現了vscode直接連接遠程的linux系統下共享的目錄,再改代碼,就能實時的聯動起來。
參考
1. centos 安裝smb :https://www.cnblogs.com/kevingrace/p/8550810.html
2. ubuntu 安裝smb: https://www.linuxidc.com/Linux/2018-11/155466.htm
3. 網絡映射到本地驅動設置 : https://jingyan.baidu.com/article/e3c78d646dfe8c3c4c85f5a9.html