Samba is software that runs on non-Windows platforms such as UNIX, Linux, IBM System 390, OpenVMS or other operating systems. Samba uses the TCP/IP protocol installed on the host. When properly configured, Samba enables a host to interact with a Windows client or server, as if the host became a Windows file and print server.
After configuring samba, you can write code under windows, submit the code, and then compile the code in the linux environment.
The installation steps are as follows:
- install samba
yum install samba
(It can be installed with apt-get install under ubuntu)
After the installation is complete, you can use
rpm -qa|grep samba command to verify that the installation was successful.
- configure samba
Modify the samba configuration file. Before modifying the configuration file, remember to make a backup copy of the configuration file to develop a good habit.
Backup using cp (copy command)
cp /etc/samba/smb.conf /etc/samba/smb.conf_backup
Then edit this config file
vim /etc/samba/smb.conf
Add at the end of the configuration file
[workspace]
path=/workspace
browseable=yes
writeable=yes
guest ok=yes
[workspace] contains the name of the file directory displayed in windows
keep
Use testparm to test the syntax of the configuration file
- restart samba
service smb restart
- Create a shared directory
mkdir /workspace
- access
It may not be accessible at this time, it may be the reason of the firewall,
Samba uses the following ports:
1) Port 137 (UDP) - NetBIOS name service; nmbd
2) Port 138 (UDP) - NetBIOS datagram service
3) Port 139 (TCP) - file and print sharing; smbd (based on SMB (Server Message Block) protocol, mainly used in local area networks, file sharing protocol)
4) Port 389 (TCP) - for LDAP (Active Directory Mode)
5) Port 445 (TCP) - NetBIOS service uses this port in windos 2000 and later versions, (Common Internet File System, CIFS, which is an extension of the SMB protocol to the Internet to achieve Internet file sharing)
6) Port 901 (TCP) - for SWAT, for web management Samba
Generally, you only need to open port 139.
Edit the iptables configuration file,
vim /etc/sysconfig/iptables
Add port 139, restart iptables,
/etc/init.d/iptables restart
Access the shared directory again, the access can be accessed, but a password is required
At this time, make some changes in smb.conf,
add below security=user
map to guest = Bad User
Restart samba. Access the shared directory again, it can be seen that the folder can be displayed
But still can't enter the folder
Because linux also allows to modify this folder, you can use the following command at this time
chcon -t samba_share_t /workspace
Mark the workspace as samba_share_t to open the folder.
But now you can't create files in the folder, this is because the anonymous user does not have the relevant permissions
Query the properties of nobody in the system
id nobody
Add anonymous users through the chown command, chown nobody:nobody /workspace
(The function of chown is to change the owner and group of the relevant directory folder, chown nobody:nobody /workspace, is to turn the owner of the workspace into a nobody anonymous user)
or
chmod 777 /workspace
(
The chmod command, the full name is change file mode bits, use ls –l to view the attributes of all files
The first one in drwxr-xr-x indicates the type, d indicates the directory, the second to fourth rwx indicates that the owner has read and write permissions, and the fifth to seventh rx indicates that the owner's group has read and execute permissions but No write permissions, eighth to tenth rx means other users have read and run permissions but no write permissions
)
At this point, the creation of the shared directory is complete.