ubuntu14.04與win8相互共享

今天遇到了大量文件轉移的問題,查找了一番,感謝 小白ing,順利共享解決。html

轉自:http://blog.csdn.net/xiaobaiing/article/details/51220310ubuntu

 

samba是Linux系統上的一種文件共享協議,能夠實現Windows系統訪問Linux系統上的共享資源,如今介紹一下如何在Ubuntu 14.04上安裝和配置samba,以及ubuntu上掛載windows共享盤的方法。此方法僅適用於ubuntu,windows兩臺不一樣的電腦,在局域網下。若是是windows與windows下虛擬機中的ubuntu(同一臺電腦),在虛擬機中設置便可。windows

1. 在ubuntu下打開終端,並輸入:sudo apt-get update網絡

2. 安裝samba服務,在終端中輸入:sudo apt-get install samba samba-common進行安裝app

3. 創建你想共享出去的文件夾,在終端中執行:mkdir /home/folder_name   (folder_name是你想共享出去的文件夾名稱)ui

4. samba安裝好以後,會在/etc/samba/文件夾下有一個smb.conf文件,此文件是samba的一個配置文件。this

5. 編輯此文件,用gedit或者vi均可以,在終端中執行:sudo gedit /etc/samba/smb.conf 或者執行:sudo vi /etc/samba/smb.conf.net

6. 在其中添加一行:   security = user ,添加這一行的目的在於,只有輸入帳號和密碼才能訪問此文件夾。添加的位置以下:rest

#### Debugging/Accounting ####  
  
# This tells Samba to use a separate log file for each machine  
# that connects  
   log file = /var/log/samba/log.%m  
  
# Cap the size of the individual log files (in KiB).  
   max log size = 1000  
   security = user  
# If you want Samba to only log through syslog then set the following  
# parameter to 'yes'.  
#   syslog only = no  
  
# We want Samba to log a minimum amount of information to syslog. Everything  
# should go to /var/log/samba/log.{smbd,nmbd} instead. If you want to log  
# through syslog you should set the following parameter to something higher.  
   syslog = 0  
  
# Do something sensible when Samba crashes: mail the admin a backtrace  
   panic action = /usr/share/samba/panic-action %d  
  
  
####### Authentication #######

7. 創建關聯你共享的文件夾,在此文件的結尾添加:code

[share]                                           //是你在windows上鍊接的時候須要的
   comment = my share directory  //描述語句
   path = /home/princess/share     //是你共享的文件夾的路徑
   browseable = yes                   
   writable = yes

添加的位置以下,,我這邊共享了三個,你也能夠同時共享多個:

# Windows clients look for this share name as a source of downloadable  
# printer drivers  
; [print$]  
   ; comment = Printer Drivers  
   ; path = /var/lib/samba/printers  
   ; browseable = yes  
   ; read only = yes  
   ; guest ok = no  
# Uncomment to allow remote administration of Windows print drivers.  
# You may need to replace 'lpadmin' with the name of the group your  
# admin users are members of.  
# Please note that you also need to set appropriate Unix permissions  
# to the drivers directory for these users to have write rights in it  
;   write list = root, @lpadmin  
  
[share]  
   comment = my share directory  
   path = /home/princess/share  
   browseable = yes  
   writable = yes  
  
[projects]  
   comment = my share directory  
   path = /home/princess/projects  
   browseable = yes  
   writable = yes  
  
[C_learn]  
   comment = my share directory  
   path = /home/princess/C_C++_learn  
   browseable = yes  
   writable = yes

  

8. samba配置完成以後,就要爲samba建了用戶了,在終端中執行:sudo useradd smbuser(在此,smbuser儘可能創建爲你如今的用戶名,否則的話對你如今用戶的全部的文件只有讀的權限。)

9. 爲你創建的smb用戶設立密碼,在終端中執行:sudo smbpasswd -a smbuser,以後輸入密碼確認。 而後重啓smb服務,在終端中執行指令:

 

$ sudo service smbd restart

  

10. 在終端中輸入ifconfig查看ubuntu的IP, 我在此以192.168.1.1爲例。

11. 以後在windows中win+R鍵調出運行,在其中輸入\\192.168.1.1,回車以後你會看到你分享出來的文件夾,雙擊輸入帳戶和密碼就能夠了。

12. 若是你想長久保存,像點擊C盤或者D盤那樣的話,就右擊個人電腦添加一個網絡位置或者映射一個網絡驅動器。以下圖

 

以後輸入\\192.168.1.1\folder_name,點擊確認,最後輸入用戶名和密碼便可。

 

 

以上是windows訪問ubuntu共享的文件夾。接下來爲大家介紹在ubuntu上訪問windows共享的文件夾:

1. 首先先確保windows電腦的IP 和ubuntu電腦的IP在同一個字段。例如
windows IP:192.168.1.8

ubuntu IP: 192.168.1.1

若是windows的IP是192.168.5.8的話,windows上能夠訪問ubuntu共享的文件夾,而ubuntu不能訪問windows共享的文件夾。換句話說,只能單向ping通。

2. 右擊你想共享出去的文件夾或者盤(好比D盤),以下圖,勾選「分享此文件夾」,以後確認便可:

 

3. 完成上面的步驟以後,就能夠在ubuntu電腦中看到了。隨便打開一個文件夾,在左下角點擊進去就能夠看到windows分享出來的文件夾了,

不過此時顯示的不是你分享出來的文件夾,而是你的電腦名,若是你不知道,你能夠在「個人電腦-->屬性」中看到,或者在cmd終端中執行指令ipconfig /all能夠看到,以下圖;

4.若是你想方便一點的話,能夠掛載到某一個文件夾下面,在ubuntu終端中執行以下命令;

 

$ sudo mount -t cifs -o uid=${UID},gid=${UID},username=xiao,password=xiao123,iocharset=utf8 //192.168.1.2/d/ /home/princess/windows_D

  

uid和gid 是爲了支持讀寫執行的權限,username和password是你windows上的用戶名和密碼,iocharset是爲了更好的支持中文,192.168.1.2是你windows的IP地址,d是你分享出來的文件夾名稱,後面的是你須要掛載到ubuntu的某個路徑,最後輸入密碼確認便可。你也能夠經過以下命令免輸密碼,echo -e "passwd\n",好比我ubuntu的密碼是  ?(兩個空格一個問號),我就能夠這樣寫,按回車便可:

echo -e "  ?\n" | sudo -S mount -t cifs -o uid=${UID},gid=${UID},username=xiao,password=xiao123,iocharset=utf8 //10.42.97.94/d/ /home/princess/windows_D

  

 

5. 最後你就能夠在你掛載的路徑下看到你分享出來的文件夾裏的內容了。吐舌頭

相關文章
相關標籤/搜索