Setup samba » Historie » Version 2
Jeremias Keihsler, 10.07.2019 08:43
1 | 1 | Jeremias Keihsler | h1. Install Procedure for samba |
---|---|---|---|
2 | |||
3 | h2. Requirements |
||
4 | |||
5 | To install samba you will need the following: |
||
6 | * a installed and supported operating system (e.g. CentOS 7.x) |
||
7 | * root-access |
||
8 | * a fast internet connection |
||
9 | |||
10 | h2. Preliminary Note |
||
11 | |||
12 | this is based on http://jehurst.wordpress.com/2011/01/17/rhel-6-for-the-clueless-samba-server/ |
||
13 | 2 | Jeremias Keihsler | and the samba for groups part is taken from https://www.techrepublic.com/article/how-to-set-up-samba-shares-for-groups/ |
14 | 1 | Jeremias Keihsler | |
15 | I’ve found a couple of tutorials on Samba, but neither one had all the right information. After fighting with it a bit, this is what I did to get it working. |
||
16 | |||
17 | h2. Install |
||
18 | |||
19 | Install Samba by logging into a Terminal as root: |
||
20 | <pre><code class="bash"> |
||
21 | yum install samba |
||
22 | </code></pre> |
||
23 | if you want to have access to samba-shares you also want to |
||
24 | <pre><code class="bash"> |
||
25 | yum install samba-client |
||
26 | </code></pre> |
||
27 | |||
28 | h2. Setup |
||
29 | |||
30 | h3. Setup SeLinux |
||
31 | |||
32 | If SeLinux is active, then it might be necessary to set some samba-related variables depending on the share-location. |
||
33 | |||
34 | This and more information can be found at http://selinuxproject.org/page/SambaRecipes |
||
35 | |||
36 | <pre><code class="bash"> |
||
37 | setsebool -P samba_domain_controller on |
||
38 | </code></pre> |
||
39 | |||
40 | The @samba_export_all@ Flag will allow to share any folder on the machine, use with care. |
||
41 | <pre><code class="bash"> |
||
42 | setsebool -P samba_export_all_rw=1 |
||
43 | </code></pre> |
||
44 | |||
45 | <pre><code class="bash"> |
||
46 | setsebool -P samba_enable_home_dirs=1 |
||
47 | </code></pre> |
||
48 | |||
49 | h3. Setup a shared directory |
||
50 | |||
51 | Create shared directory; I used /home/shared: |
||
52 | |||
53 | <pre><code class="bash"> |
||
54 | mkdir /home/shared |
||
55 | chmod a+w /home/shared |
||
56 | chcon -t samba_share_t /home/shared |
||
57 | </code></pre> |
||
58 | |||
59 | That last line insures the SELinux security system knows to allow outside systems to poke around in that folder. Now anyone using this computer can move files in and out of the folder, as well as the Samba users. |
||
60 | |||
61 | h3. Setup a samba user |
||
62 | |||
63 | Add a Samba user. This is a different task than simply adding a user account. There is a GUI tool for adding Linux user accounts to the machine for them to use the computer itself. However, Samba users must be handled differently, so that the system forces them to use the Samba server. |
||
64 | |||
65 | <pre><code class="bash"> |
||
66 | useradd -c "Real Name" -d /home/samba-username -s /sbin/nologin samba-username |
||
67 | </code></pre> |
||
68 | |||
69 | That’s all one line. As usual, substitute the actual Real Name and samba-username in the command above. Then create the Samba password. Remember what we said about coming up with good passwords: |
||
70 | |||
71 | <pre><code class="bash"> |
||
72 | smbpasswd -a samba-username |
||
73 | </code></pre> |
||
74 | |||
75 | It will prompt for the password, which you type in blindly: |
||
76 | |||
77 | <pre><code class="bash"> |
||
78 | New SMB password: |
||
79 | Retype new SMB password: |
||
80 | Added user username. |
||
81 | </code></pre> |
||
82 | |||
83 | Edit smbusers: |
||
84 | <pre><code class="bash"> |
||
85 | vim /etc/samba/smbusers |
||
86 | </code></pre> |
||
87 | |||
88 | This will open the default text editor. Scan down the file until you see something like this: |
||
89 | |||
90 | <pre><code class="bash"> |
||
91 | root = administrator admin |
||
92 | nobody = guest pcguest smbguest |
||
93 | </code></pre> |
||
94 | |||
95 | Immediately below this, add a line with this format: |
||
96 | |||
97 | <pre><code class="bash"> |
||
98 | username = samba-username |
||
99 | </code></pre> |
||
100 | |||
101 | so CentOS recognizes the person logging in from the Winbox by their samba-username. |
||
102 | |||
103 | h3. Setup a samba config |
||
104 | |||
105 | Then open: |
||
106 | <pre><code class="bash"> |
||
107 | vim /etc/samba/smb.conf |
||
108 | </code></pre> |
||
109 | Find the section headed '[global]'. Change the workgroup name to whatever your Windows computer will be seeking. Default is workgroup in lower case letters. You’ll need to remove the semicolon in front of the next line and provide a proper hostname for the netbios name, which would be the name you gave your RHEL computer during installation, again in lower case. Remove the semicolon from the next line and the IP address numbers from the sample; all we need are the two interfaces lo eth0. Below that is a line with hostsallow as a model. Below that, start a new line with the same indentation: |
||
110 | |||
111 | <pre><code class="bash"> |
||
112 | hosts allow = 127. 192.168.1. |
||
113 | </code></pre> |
||
114 | |||
115 | The “127.” is the IP address for everything on your own machine. The other (192.168.1.) is the private LAN network I use for my home router; by leaving off the last section after the dot, it automatically includes every computer with that prefix, which is reserved for LANs. |
||
116 | |||
117 | If you want to bind to specific interfaces only you maybe want to consider |
||
118 | <pre><code class="bash"> |
||
119 | interfaces = lo vboxnet0 192.168.56.1/24 |
||
120 | bind interfaces only = yes |
||
121 | </code></pre> |
||
122 | |||
123 | Go all the way to the bottom of the file and add some lines. I named my shared directory “shared”. Thus, the section heading should be named the same: |
||
124 | |||
125 | <pre><code class="ini"> |
||
126 | [shared] |
||
127 | path = /home/shared |
||
128 | writeable = yes |
||
129 | browseable = yes |
||
130 | read only = No |
||
131 | guest ok = Yes |
||
132 | public = Yes |
||
133 | valid users = username1 username2 |
||
134 | create mask = 0666 |
||
135 | directory mask = 0777 |
||
136 | </code></pre> |
||
137 | |||
138 | if you want to have a trash-bin on the share, you might consider adding following section: |
||
139 | <pre><code class="bash"> |
||
140 | vfs object = recycle |
||
141 | recycle:repository = .deleted/%U |
||
142 | recycle:keeptree = Yes |
||
143 | recycle:touch = Yes |
||
144 | recycle:versions = Yes |
||
145 | recycle:maxsixe = 0 |
||
146 | recycle:exclude = *.tmp |
||
147 | recycle:exclude_dir = /tmp |
||
148 | recycle:noversions = *.bak |
||
149 | </code></pre> |
||
150 | |||
151 | h2. Firewall |
||
152 | |||
153 | Now change the firewall to allow Samba to get through. You can use the tool in System > Administration > Firewall. Simply scan down the list to Samba and checkmark the box. Optionally checkmark IPP printer sharing. Then hit “Apply”. |
||
154 | <pre><code class="bash"> |
||
155 | firewall-config |
||
156 | </code></pre> |
||
157 | or in Textmode |
||
158 | <pre><code class="bash"> |
||
159 | firewall-cmd |
||
160 | </code></pre> |
||
161 | |||
162 | <pre><code class="bash"> |
||
163 | firewall-cmd --permanent --zone=public --add-service=samba |
||
164 | firewall-cmd --reload |
||
165 | </code></pre> |
||
166 | |||
167 | h2. Service |
||
168 | |||
169 | enable and start of the services with |
||
170 | <pre><code class="bash"> |
||
171 | systemctl enable smb.service |
||
172 | systemctl enable nmb.service |
||
173 | systemctl restart smb.service |
||
174 | systemctl restart nmb.service |
||
175 | </code></pre> |
||
176 | |||
177 | h2. Test |
||
178 | |||
179 | following commands might be helpful: |
||
180 | <pre><code class="bash"> |
||
181 | findsmb |
||
182 | smbclient //host/share -U username |
||
183 | </code></pre> |