-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorigproc.sh
More file actions
executable file
·427 lines (234 loc) · 18 KB
/
origproc.sh
File metadata and controls
executable file
·427 lines (234 loc) · 18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
################################################################################
# #
# Katabasis is licensed under the GNU General Public License, version 2.0. #
# #
################################################################################
################################################################################
# #
# *++*+++***+**++*+++*|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|*+++*++**+***+++*++* #
# ++*+++***+**++*+++**|%%%| |%%%|**+++*++**+***+++*++ #
# +*+++***+**++*+++***|%%%| preA |%%%|***+++*++**+***+++*+ #
# *+++***+**++*+++***+|%%%| K A T A B A S I S |%%%|+***+++*++**+***+++* #
# +++***+**++*+++***++|%%%| |%%%|++***+++*++**+***+++ #
# ++***+**++*+++***+++|%%%| |%%%|+++***+++*++**+***++ #
# +***+**++*+++***+++*|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|*+++***+++*++**+***+ #
# #
# You will need the following information: #
# ~ your email address (hereafter: <email_addr>) #
# ~ your server's internet protocol address (hereafter: <vps_ip_addr>) #
# ~ your server's name (hereafter: <vps_name>) #
# #
# Be advised: #
# ~ <os_username> must be a string that is not "root" #
# ~ <os_password> should be a string that is longer than eight characters #
# ~ <defined_ssh_port> must be an integer that is between 1024 and 65535 #
# #
################################################################################
# ::|\ _______ /|::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: #
# ::| | | |::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: #
# ::| | local | |::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: #
# ::| !_______! |::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: #
# ::!/ \!::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: #
ssh-keygen -t rsa
sh -c 'echo "<os_username>:<os_password>" >> .credentials'
ssh root@<vps_ip_addr>
# ::|\ ________ /|:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: #
# ::| | | |:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: #
# ::| | remote | |:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: #
# ::| !________! |:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: #
# ::!/ \!:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: #
yes
sh -c 'echo "set const" >> .nanorc'
sh -c 'echo "set tabsize 8" >> .nanorc'
sh -c 'echo "set tabstospaces" >> .nanorc'
adduser --disabled-password --gecos "" <os_username>
usermod -aG sudo <os_username>
cp .nanorc /home/<os_username>/
mkdir /etc/ssh/<os_username>
exit
# ::|\ _______ /|::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: #
# ::| | | |::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: #
# ::| | local | |::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: #
# ::| !_______! |::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: #
# ::!/ \!::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: #
scp .ssh/id_rsa.pub root@<vps_ip_addr>:/etc/ssh/<os_username>/authorized_keys
scp .credentials root@<vps_ip_addr>:/home/<os_username>/
ssh root@<vps_ip_addr>
# ::|\ ________ /|:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: #
# ::| | | |:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: #
# ::| | remote | |:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: #
# ::| !________! |:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: #
# ::!/ \!:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: #
chown -R <os_username>:<os_username> /etc/ssh/<os_username>
chmod 755 /etc/ssh/<os_username>
chmod 644 /etc/ssh/<os_username>/authorized_keys
sed -i -e '/^#AuthorizedKeysFile/s/^.*$/AuthorizedKeysFile \/etc\/ssh\/<os_username>\/authorized_keys/' /etc/ssh/sshd_config
sed -i -e '/^PermitRootLogin/s/^.*$/PermitRootLogin no/' /etc/ssh/sshd_config
sed -i -e '/^PasswordAuthentication/s/^.*$/PasswordAuthentication no/' /etc/ssh/sshd_config
sh -c 'echo "" >> /etc/ssh/sshd_config'
sh -c 'echo "" >> /etc/ssh/sshd_config'
sh -c 'echo "# Added by Katabasis build process" >> /etc/ssh/sshd_config'
sh -c 'echo "AllowUsers <os_username>" >> /etc/ssh/sshd_config'
systemctl reload sshd
apt-get -y install firewalld
systemctl start firewalld
firewall-cmd --reload
systemctl enable firewalld
sed -i -e '/^Port/s/^.*$/Port <defined_ssh_port>/' /etc/ssh/sshd_config
firewall-cmd --add-port <defined_ssh_port>/tcp --permanent
firewall-cmd --reload
systemctl reload sshd
timedatectl set-timezone America/New_York
apt-get -y install ntp
fallocate -l 3G /swapfile
chmod 600 /swapfile
mkswap /swapfile
sh -c "echo '/swapfile none swap sw 0 0' >> /etc/fstab"
sysctl vm.swappiness=10
sh -c "echo 'vm.swappiness=10' >> /etc/sysctl.conf"
sysctl vm.vfs_cache_pressure=30
sh -c 'echo "vm.vfs_cache_pressure=30" >> /etc/sysctl.conf'
apt-get -y install nginx
sh -c 'echo "log_format timekeeper \$remote_addr - \$remote_user [\$time_local] " >> /etc/nginx/conf.d/timekeeper-log-format.conf'
sed -i "s/\$remote_addr/\'\$remote_addr/" /etc/nginx/conf.d/timekeeper-log-format.conf
sed -i "s/_local] /_local] \'/" /etc/nginx/conf.d/timekeeper-log-format.conf
sh -c 'echo " \$request \$status \$body_bytes_sent " >> /etc/nginx/conf.d/timekeeper-log-format.conf'
sed -i "s/\$request/\'\"\$request\"/" /etc/nginx/conf.d/timekeeper-log-format.conf
sed -i "s/_sent /_sent \'/" /etc/nginx/conf.d/timekeeper-log-format.conf
sh -c 'echo " \$http_referer \$http_user_agent \$http_x_forwarded_for \$request_time;" >> /etc/nginx/conf.d/timekeeper-log-format.conf'
sed -i "s/\$http_referer/\'\"\$http_referer\"/" /etc/nginx/conf.d/timekeeper-log-format.conf
sed -i "s/\$http_user_agent/\"\$http_user_agent\"/" /etc/nginx/conf.d/timekeeper-log-format.conf
sed -i "s/\$http_x_forwarded_for/\"\$http_x_forwarded_for\"/" /etc/nginx/conf.d/timekeeper-log-format.conf
sed -i "s/_time;/_time\';/" /etc/nginx/conf.d/timekeeper-log-format.conf
sh -c 'echo "geoip_country /usr/share/GeoIP/GeoIP.dat;" >> /etc/nginx/conf\.d/geoip.conf'
sed -i '/# Default server configuration/a \}' /etc/nginx/sites-available/default
sed -i '/# Default server configuration/a US yes;' /etc/nginx/sites-available/default
sed -i '/# Default server configuration/a default no;' /etc/nginx/sites-available/default
sed -i '/# Default server configuration/a map \$geoip_country_code \$allowed_country \{' /etc/nginx/sites-available/default
sed -i '/# Default server configuration/a \
' /etc/nginx/sites-available/default
sed -i 's/US yes;/ US yes;/' /etc/nginx/sites-available/default
sed -i 's/default no;/ default no;/' /etc/nginx/sites-available/default
sed -i '/listen \[::\]:80 default_server;/a \}#tmp_id_1' /etc/nginx/sites-available/default
sed -i '/listen \[::\]:80 default_server;/a return 444;' /etc/nginx/sites-available/default
sed -i '/listen \[::\]:80 default_server;/a if (\$allowed_country = no) \{' /etc/nginx/sites-available/default
sed -i '/listen \[::\]:80 default_server;/a \
' /etc/nginx/sites-available/default
sed -i 's/\}#tmp_id_1/ \}/' /etc/nginx/sites-available/default
sed -i 's/return 444;/ return 444;/' /etc/nginx/sites-available/default
sed -i 's/if (\$allowed_country = no)/ if (\$allowed_country = no)/' /etc/nginx/sites-available/default
sed -i '/listen \[::\]:80 default_server;/a access_log \/var\/log\/nginx\/server-block-1-access\.log timekeeper gzip;' /etc/nginx/sites-available/default
sed -i 's/access_log \/var\/log\/nginx\/server-block-1-access\.log timekeeper gzip;/ access_log \/var\/log\/nginx\/server-block-1-access\.log timekeeper gzip;/' /etc/nginx/sites-available/default
sed -i '/access_log \/var\/log\/nginx\/server-block-1-access\.log timekeeper gzip;/a error_log \/var\/log\/nginx\/server-block-1-error\.log;' /etc/nginx/sites-available/default
sed -i 's/error_log \/var\/log\/nginx\/server-block-1-error\.log;/ error_log \/var\/log\/nginx\/server-block-1-error\.log;/' /etc/nginx/sites-available/default
sed -i '/listen \[::\]:80 default_server;/a \
' /etc/nginx/sites-available/default
# sed -i -e '/^# server {/s/^.*$/ server {/' /etc/nginx/nginx.conf
# sed -i -e '/^# listen 443 ssl http2 default_server;/s/^.*$/ listen 443 ssl http2 default_server;/' /etc/nginx/nginx.conf
# sed -i -e '/^# listen \[::\]:443 ssl http2 default_server;/s/^.*$/ listen \[::\]:443 ssl http2 default_server;/' /etc/nginx/nginx.conf
# sed -i -e '/^# server_name _;/s/^.*$/ server_name _;/' /etc/nginx/nginx.conf
# sed -i -e '/^# root \/usr\/share\/nginx\/html;/s/^.*$/ root \/usr\/share\/nginx\/html;#tmp_id_2/' /etc/nginx/nginx.conf
# sed -i '/^ root \/usr\/share\/nginx\/html;#tmp_id_2/a resolver 8\.8\.8\.8 8\.8\.4\.4 208\.67\.222\.222 208\.67\.220\.220 216\.146\.35\.35 216\.146\.36\.36 valid=300s;' /etc/nginx/nginx.conf
# sed -i 's/resolver 8\.8\.8\.8 8\.8\.4\.4 208\.67\.222\.222 208\.67\.220\.220 216\.146\.35\.35 216\.146\.36\.36 valid=300s;/ resolver 8\.8\.8\.8 8\.8\.4\.4 208\.67\.222\.222 208\.67\.220\.220 216\.146\.35\.35 216\.146\.36\.36 valid=300s;/' /etc/nginx/nginx.conf
# sed -i '/^ resolver 8\.8\.8\.8 8\.8\.4\.4 208\.67\.222\.222 208\.67\.220\.220 216\.146\.35\.35 216\.146\.36\.36 valid=300s;/a resolver_timeout 3s;' /etc/nginx/nginx.conf
# sed -i 's/resolver_timeout 3s;/ resolver_timeout 3s;/' /etc/nginx/nginx.conf
# sed -i '/^ root \/usr\/share\/nginx\/html;#tmp_id_2/a \
# #' /etc/nginx/nginx.conf
# sed -i '/^ root \/usr\/share\/nginx\/html;#tmp_id_2/a # add_header Strict-Transport-Security \"max-age=31536000; includeSubDomains; preload\";' /etc/nginx/nginx.conf
# sed -i '/^ root \/usr\/share\/nginx\/html;#tmp_id_2/a add_header Strict-Transport-Security \"max-age=31536000\";' /etc/nginx/nginx.conf
# sed -i 's/add_header Strict-Transport-Security \"max-age=31536000\";/ add_header Strict-Transport-Security \"max-age=31536000\";/' /etc/nginx/nginx.conf
# sed -i '/^ root \/usr\/share\/nginx\/html;#tmp_id_2/a add_header X-Frame-Options DENY;' /etc/nginx/nginx.conf
# sed -i 's/add_header X-Frame-Options DENY;/ add_header X-Frame-Options DENY;/' /etc/nginx/nginx.conf
# sed -i '/^ root \/usr\/share\/nginx\/html;#tmp_id_2/a add_header X-Content-Type-Options nosniff;' /etc/nginx/nginx.conf
# sed -i 's/add_header X-Content-Type-Options nosniff;/ add_header X-Content-Type-Options nosniff;/' /etc/nginx/nginx.conf
# sed -i '/^ root \/usr\/share\/nginx\/html;#tmp_id_2/a \
# #' /etc/nginx/nginx.conf
# sed -i -e '/^# ssl_certificate "\/etc\/pki\/nginx\/server\.crt";/s/^.*$/ ssl_certificate "\/etc\/pki\/nginx\/server\.crt";/' /etc/nginx/nginx.conf
# sed -i -e '/^# ssl_certificate_key "\/etc\/pki\/nginx\/private\/server\.key";/s/^.*$/ ssl_certificate_key "\/etc\/pki\/nginx\/private\/server\.key";#tmp_id_6/' /etc/nginx/nginx.conf
# sed -i '/^ ssl_certificate_key \"\/etc\/pki\/nginx\/private\/server\.key\";#tmp_id_6/a ssl_protocols TLSv1 TLSv1\.1 TLSv1\.2;' /etc/nginx/nginx.conf
# sed -i 's/ssl_protocols TLSv1 TLSv1\.1 TLSv1\.2;/ ssl_protocols TLSv1 TLSv1\.1 TLSv1\.2;/' /etc/nginx/nginx.conf
# sed -i '/^ ssl_certificate_key \"\/etc\/pki\/nginx\/private\/server\.key\";#tmp_id_6/a ssl_ecdh_curve secp384r1;' /etc/nginx/nginx.conf
# sed -i 's/ssl_ecdh_curve secp384r1;/ ssl_ecdh_curve secp384r1;/' /etc/nginx/nginx.conf
# sed -i -e '/^# ssl_session_cache shared:SSL:1m;/s/^.*$/ ssl_session_cache shared:SSL:1m;/' /etc/nginx/nginx.conf
# sed -i -e '/^# ssl_session_timeout 10m;/s/^.*$/ ssl_session_timeout 10m;/' /etc/nginx/nginx.conf
# sed -i -e '/^# ssl_ciphers HIGH:!aNULL:!MD5;/s/^.*$/ ssl_ciphers \"EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH\";/' /etc/nginx/nginx.conf
# sed -i -e '/^# ssl_prefer_server_ciphers on;/s/^.*$/ ssl_prefer_server_ciphers on;/' /etc/nginx/nginx.conf
# sed -i -e '/^# # Load configuration files for the default server block\./s/^.*$/ # Load configuration files for the default server block\./' /etc/nginx/nginx.conf
# sed -i -e '/^# include \/etc\/nginx\/default\.d\/\*\.conf;/s/^.*$/ include \/etc\/nginx\/default\.d\/\*\.conf;#tmp_id_3/' /etc/nginx/nginx.conf
# sed -i '/^ include \/etc\/nginx\/default\.d\/\*\.conf;#tmp_id_3/a \}#tmp_id_7' /etc/nginx/nginx.conf
# sed -i 's/\}#tmp_id_7/ \}#tmp_id_7/' /etc/nginx/nginx.conf
# sed -i '/^ include \/etc\/nginx\/default\.d\/\*\.conf;#tmp_id_3/a return 444;#tmp_id_4' /etc/nginx/nginx.conf
# sed -i 's/return 444;#tmp_id_4/ return 444;#tmp_id_4/' /etc/nginx/nginx.conf
# sed -i '/^ include \/etc\/nginx\/default\.d\/\*\.conf;#tmp_id_3/a if (\$allowed_country = no) \{#tmp_id_8' /etc/nginx/nginx.conf
# sed -i 's/if (\$allowed_country = no) {#tmp_id_8/ if (\$allowed_country = no) {#tmp_id_8/' /etc/nginx/nginx.conf
# sed -i '/^ include \/etc\/nginx\/default\.d\/\*\.conf;#tmp_id_3/a \
# #' /etc/nginx/nginx.conf
# sed -i '/^ include \/etc\/nginx\/default\.d\/\*\.conf;#tmp_id_3/a access_log \/var\/log\/nginx\/server-block-1-access.log timekeeper;#tmp_id_9' /etc/nginx/nginx.conf
# sed -i -e 's/access_log \/var\/log\/nginx\/server-block-1-access.log timekeeper;#tmp_id_9/ access_log \/var\/log\/nginx\/server-block-1-access.log timekeeper;#tmp_id_9/' /etc/nginx/nginx.conf
# sed -i '/access_log \/var\/log\/nginx\/server-block-1-access.log timekeeper;#tmp_id_9/a error_log \/var\/log\/nginx\/server-block-1-error.log;#tmp_id_10' /etc/nginx/nginx.conf
# sed -i -e 's/error_log \/var\/log\/nginx\/server-block-1-error.log;#tmp_id_10/ error_log \/var\/log\/nginx\/server-block-1-error.log;#tmp_id_10/' /etc/nginx/nginx.conf
# sed -i '/^ include \/etc\/nginx\/default\.d\/\*\.conf;#tmp_id_3/a \
# #' /etc/nginx/nginx.conf
# sed -i -e '/^# location \/ {/s/^.*$/ location \/ {/' /etc/nginx/nginx.conf
# sed -i -e '/^# }/s/^.*$/ }/' /etc/nginx/nginx.conf
# sed -i -e '/^# error_page 404 \/404.html;/s/^.*$/ error_page 404 \/404.html;/' /etc/nginx/nginx.conf
# sed -i -e '/^# location = \/40x.html {/s/^.*$/ location = \/40x.html {/' /etc/nginx/nginx.conf
# sed -i -e '/^# error_page 500 502 503 504 \/50x.html;/s/^.*$/ error_page 500 502 503 504 \/50x.html;/' /etc/nginx/nginx.conf
# sed -i -e '/^# location = \/50x.html {/s/^.*$/ location = \/50x.html {/' /etc/nginx/nginx.conf
# sed -i -e '/^# }/s/^.*$/ }/' /etc/nginx/nginx.conf
sh -c "echo 'gzip_vary on;' >> /etc/nginx/conf.d/gzip.conf"
sh -c "echo 'gzip_proxied any;' >> /etc/nginx/conf.d/gzip.conf"
sh -c "echo 'gzip_comp_level 6;' >> /etc/nginx/conf.d/gzip.conf"
sh -c "echo 'gzip_buffers 16 8k;' >> /etc/nginx/conf.d/gzip.conf"
sh -c "echo 'gzip_http_version 1.1;' >> /etc/nginx/conf.d/gzip.conf"
sh -c "echo 'gzip_min_length 256;' >> /etc/nginx/conf.d/gzip.conf"
sh -c "echo 'gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript application/vnd.ms-fontobject application/x-font-ttf font/opentype image/svg+xml image/x-icon;' >> /etc/nginx/conf.d/gzip.conf"
nginx -t
systemctl start nginx
firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload
systemctl enable nginx
apt-get -y install fail2ban
systemctl enable fail2ban
sh -c 'echo "[DEFAULT]" >> /etc/fail2ban/jail.local'
sh -c 'echo "bantime = 7200" >> /etc/fail2ban/jail.local'
sh -c 'echo "findtime = 1200" >> /etc/fail2ban/jail.local'
sh -c 'echo "maxretry = 3" >> /etc/fail2ban/jail.local'
sh -c 'echo "destemail = <email_addr>" >> /etc/fail2ban/jail.local'
sh -c 'echo "sendername = security@<vps_name>" >> /etc/fail2ban/jail.local'
sh -c 'echo "banaction = iptables-multiport" >> /etc/fail2ban/jail.local'
sh -c 'echo "mta = sendmail" >> /etc/fail2ban/jail.local'
sh -c 'echo "action = %(banaction)s[name=%(__name__)s, bantime=\"%(bantime)s\", port=\"%(port)s\", protocol=\"%(protocol)s\", chain=\"%(chain)s\"], %(mta)s-whois-lines[name=%(__name__)s, dest=\"%(destemail)s\", logpath=%(logpath)s, chain=\"%(chain)s\"]" >> /etc/fail2ban/jail.local'
sh -c 'echo "" >> /etc/fail2ban/jail.local'
sh -c 'echo "[sshd]" >> /etc/fail2ban/jail.local'
sh -c 'echo "enabled = true" >> /etc/fail2ban/jail.local'
sh -c 'echo "" >> /etc/fail2ban/jail.local'
sh -c 'echo "" >> /etc/fail2ban/jail.local'
sh -c 'echo "[sshd-ddos]" >> /etc/fail2ban/jail.local'
sh -c 'echo "enabled = true" >> /etc/fail2ban/jail.local'
sh -c 'echo "" >> /etc/fail2ban/jail.local'
sh -c 'echo "[nginx-http-auth]" >> /etc/fail2ban/jail.local'
sh -c 'echo "enabled = true" >> /etc/fail2ban/jail.local'
systemctl restart fail2ban
cat /home/<os_username>/.credentials | chpasswd
rm /home/<os_username>/.credentials
sudo apt-get -y install postgresql postgresql-contrib
su - postgres
psql
CREATE USER <os_username> WITH PASSWORD '<os_password>';
CREATE DATABASE master OWNER <os_username>;
\q
su - <os_username>
<os_password>
psql master
CREATE TABLE market (
pk serial PRIMARY KEY,
time float,
open float,
high float,
low float,
close float,
volume integer
);
git clone git://github.com/katabasis/katabasis.git