-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnewServer.sh
232 lines (167 loc) · 4.9 KB
/
newServer.sh
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
#!/bin/bash
if [ -z $1 ]; then
echo "Empty param - username";
exit;
else
USERNAME_LOCAL=$1
fi
if id -u "$USERNAME_LOCAL" >/dev/null 2>&1; then
echo "user exist";
else
adduser "$USERNAME_LOCAL"
#clear
echo "Не забудь про visudo"
echo "$USERNAME_LOCAL ALL=(ALL:ALL) ALL"
sleep 2;
#visudo
#su "$USERNAME_LOCAL"
echo "перейди на нового пользователя и запусти скрипт снова";
mv "$0" /home/"$USERNAME_LOCAL"/
chown "$USERNAME_LOCAL":"$USERNAME_LOCAL" /home/"$USERNAME_LOCAL"/"$0"
exit;
fi
while true; do
read -p "Нужен SWAP? [y/n] " yn
case $yn in
[Yy]* ) sudo /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024;sudo /sbin/mkswap /var/swap.1;sudo /sbin/swapon /var/swap.1; break;;
[Nn]* ) break;;
* ) echo "Только y или n";;
esac
done
sudo apt install --no-install-recommends php8.1
sudo apt-get install php8.1 php8.1-dev php8.1-xml php8.1-zip php8.1-gmp php8.1-cli php8.1-mbstring php8.1-common php8.1-mysql php8.1-xml php8.1-xmlrpc php8.1-curl php8.1-gd php8.1-imagick php8.1-cli php8.1-dev php8.1-imap php8.1-mbstring php8.1-opcache php8.1-soap php8.1-zip php8.1-intl git -y
sudo apt install curl -y
sudo apt install mc -y
sudo apt install vim -y
sudo apt install wget -y
sudo apt install git -y
sudo apt install htop -y
sudo apt install net-tools -y
sudo apt-get install bash-completion -y
#echo '. /etc/bash_completion' >> ~/.bashrc
curl -sS https://getcomposer.org/installer -o composer-setup.php
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
rm composer-setup.php
sudo apt update -y
sudo apt upgrade -y
sudo apt install apache2 -y
#alias and env config
cd ~
echo "
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -hl'
alias ls='ls --color=auto'
PS1='\[\033[1;36m\]\u\[\033[1;31m\]@\[\033[1;32m\]\h:\[\033[1;35m\]\w\[\033[1;31m\]\$\[\033[0m\] '
" >> .bashrc
#end alias
#remember
cd ~
ssh-keygen -t rsa -b 2048
FILE=/home/"$USERNAME_LOCAL"/.ssh
if [ -f "$FILE" ]; then
echo "$FILE exist"
else
mkdir .ssh
fi
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
rm ~/.ssh/id_rsa.pub
echo '
# Package generated configuration file
# See the sshd_config(5) manpage for details
# What ports, IPs and protocols we listen for
Port 5499
# Use these options to restrict which interfaces/protocols sshd will bind to
#ListenAddress ::
#ListenAddress 0.0.0.0
Protocol 2
# HostKeys for protocol version 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
#Privilege Separation is turned on for security
UsePrivilegeSeparation yes
# Lifetime and size of ephemeral version 1 server key
KeyRegenerationInterval 3600
ServerKeyBits 1024
# Logging
SyslogFacility AUTH
LogLevel INFO
# Authentication:
LoginGraceTime 120
PermitRootLogin no
StrictModes yes
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile %h/.ssh/authorized_keys %h/.ssh/id_rsa.pub
IgnoreRhosts yes
# For this to work you will also need host keys in /etc/ssh_known_hosts
RhostsRSAAuthentication no
# similar for protocol version 2
HostbasedAuthentication no
#IgnoreUserKnownHosts yes
# To enable empty passwords, change to yes (NOT RECOMMENDED)
PermitEmptyPasswords no
# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication no
# Change to no to disable tunnelled clear text passwords
PasswordAuthentication no
# Kerberos options
#KerberosAuthentication no
#KerberosGetAFSToken no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes
X11Forwarding yes
X11DisplayOffset 10
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes
UseLogin no
#MaxStartups 10:30:60
#Banner /etc/issue.net
# Allow client to pass locale environment variables
AcceptEnv LANG LC_*
Subsystem sftp /usr/lib/openssh/sftp-server
UsePAM yes
' | sudo tee /etc/ssh/sshd_config
chmod 700 ~/.ssh/
chmod 600 ~/.ssh/authorized_keys
sudo service sshd restart
sudo ufw deny 22
sudo ufw allow 80
sudo ufw allow 5499
sudo ufw allow 443
sudo ufw allow 8888
sudo ufw enable
sudo chsh -s /bin/bash "$USERNAME_LOCAL"
sudo update-alternatives --config editor
#end remember
#ssh-keygen
#locale
sudo apt install language-pack-ru -y
sudo update-locale LANG=ru_RU.UTF-8
#sudo dpkg-reconfigure locales
#end locale
#mysql only
while true; do
read -p "Нужен mysql? [y/n] " yn
case $yn in
[Yy]* ) sudo apt update -y;sudo apt install mysql-server -y;sudo mysql_secure_installation -y; sudo add-apt-repository ppa:phpmyadmin/ppa;
sudo apt install phpmyadmin php-mbstring php-gettext -y; break;;
[Nn]* ) break;;
* ) echo "Только y или n";;
esac
done
#####
clear
cat ~/.ssh/id_rsa
rm ~/.ssh/id_rsa
rm "$0"