Projekt

Allgemein

Profil

Setup samba » Historie » Version 1

Jeremias Keihsler, 12.01.2017 12:09

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
14
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.
15
16
h2. Install 
17
18
Install Samba by logging into a Terminal as root:
19
<pre><code class="bash">
20
yum install samba
21
</code></pre>
22
if you want to have access to samba-shares you also want to
23
<pre><code class="bash">
24
yum install samba-client
25
</code></pre>
26
27
h2. Setup 
28
29
h3. Setup SeLinux
30
31
If SeLinux is active, then it might be necessary to set some samba-related variables depending on the share-location.
32
33
This and more information can be found at http://selinuxproject.org/page/SambaRecipes
34
35
<pre><code class="bash">
36
setsebool -P samba_domain_controller on
37
</code></pre>
38
39
The @samba_export_all@ Flag will allow to share any folder on the machine, use with care.
40
<pre><code class="bash">
41
setsebool -P samba_export_all_rw=1
42
</code></pre>
43
44
<pre><code class="bash">
45
setsebool -P samba_enable_home_dirs=1
46
</code></pre>
47
48
h3. Setup a shared directory
49
50
Create shared directory; I used /home/shared:
51
52
<pre><code class="bash">
53
mkdir /home/shared
54
chmod a+w /home/shared
55
chcon -t samba_share_t /home/shared
56
</code></pre>
57
58
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.
59
60
h3. Setup a samba user
61
62
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.
63
64
<pre><code class="bash">
65
useradd -c "Real Name" -d /home/samba-username -s /sbin/nologin samba-username
66
</code></pre>
67
68
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:
69
70
<pre><code class="bash">
71
smbpasswd -a samba-username
72
</code></pre>
73
74
It will prompt for the password, which you type in blindly:
75
76
<pre><code class="bash">
77
New SMB password:
78
Retype new SMB password:
79
Added user username.
80
</code></pre>
81
82
Edit smbusers:
83
<pre><code class="bash">
84
vim /etc/samba/smbusers
85
</code></pre>
86
87
This will open the default text editor. Scan down the file until you see something like this:
88
89
<pre><code class="bash">
90
root = administrator admin
91
nobody = guest pcguest smbguest
92
</code></pre>
93
94
Immediately below this, add a line with this format:
95
96
<pre><code class="bash">
97
username = samba-username
98
</code></pre>
99
100
so CentOS recognizes the person logging in from the Winbox by their samba-username.
101
102
h3. Setup a samba config
103
104
Then open: 
105
<pre><code class="bash">
106
vim /etc/samba/smb.conf
107
</code></pre>
108
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:
109
110
<pre><code class="bash">
111
hosts allow = 127. 192.168.1.
112
</code></pre>
113
114
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.
115
116
If you want to bind to specific interfaces only you maybe want to consider
117
<pre><code class="bash">
118
interfaces = lo vboxnet0 192.168.56.1/24
119
bind interfaces only = yes
120
</code></pre>
121
122
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:
123
124
<pre><code class="ini">
125
[shared]
126
path = /home/shared
127
writeable = yes
128
browseable = yes
129
read only = No
130
guest ok = Yes
131
public = Yes
132
valid users = username1 username2
133
create mask = 0666
134
directory mask = 0777
135
</code></pre>
136
137
if you want to have a trash-bin on the share, you might consider adding following section:
138
<pre><code class="bash">
139
vfs object = recycle
140
  recycle:repository = .deleted/%U
141
  recycle:keeptree = Yes
142
  recycle:touch = Yes
143
  recycle:versions = Yes
144
  recycle:maxsixe = 0
145
  recycle:exclude = *.tmp
146
  recycle:exclude_dir = /tmp
147
  recycle:noversions = *.bak
148
</code></pre>
149
150
h2. Firewall
151
152
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”.
153
<pre><code class="bash">
154
firewall-config
155
</code></pre>
156
or in Textmode
157
<pre><code class="bash">
158
firewall-cmd
159
</code></pre>
160
161
<pre><code class="bash">
162
firewall-cmd --permanent --zone=public --add-service=samba
163
firewall-cmd --reload
164
</code></pre>
165
166
h2. Service
167
168
enable and start of the services with
169
<pre><code class="bash">
170
systemctl enable smb.service
171
systemctl enable nmb.service
172
systemctl restart smb.service
173
systemctl restart nmb.service
174
</code></pre>
175
176
h2. Test 
177
178
following commands might be helpful:
179
<pre><code class="bash">
180
findsmb
181
smbclient //host/share -U username
182
</code></pre>