Увод
Корак 1 - Припрема система
Корак 2 - Инсталирање Гуацамоле
Корак 3 - Фино подешавање и чишћење
Корак 4 (опција А) - Покреће се само на ХТТП-у
Корак 5 (опција Б) - Подешавање Нгинк-а
Корак 6 - Тестирајте све
Закључак
Увод
Циљ овог туторијала је да се отарасите јавних ССХ и јавних РДП веза. Стављајући све ово иза веома згодног ХТМЛ5 клијента, можемо додати ниво безбедности за приступ нашем облаку.
Гуацамоле такође бележи сваки даљински приступ, тако да неовлашћени приступ постаје много лакше следљив.
Напомена: За Лет'с енцрипт (опција Б) потребно нам је име домена. Ако немате, можете да прескочите овај корак и само извршава опција .
Корак 1 - Припрема система
Започните окретањем ВПС-а у жељеној Вултр зони. 1024 MBВпс ће бити довољно, јер Гуакамоле није тако захтеван.
Омогућавање приватне ИП адресе
Почните тако што ћете омогућити приватну мрежу на ВПС-у. Ово је добро документован овде
Припрема заштитног зида
Прво да мало ојачамо слику. И хајде да проверимо да ли је ufwомогућена слика која је обезбеђена .
root@vultr:~# ufw status
Status: inactive
Подразумевано је онемогућено, тако да ћемо морати да додамо неколико правила.
- Правило 1: ссх: ТЦП порт 22
- Правило 2: хттп: ТЦП порт 8080 (привремено правило тестирања за Гуацамоле)
Почнимо са конфигурисањем ових портова.
ufw allow 22/tcp
ufw allow 8080/tcp
Затим омогућите заштитни зид.
ufw enable
Не брините ако добијете упозорење. Ако сте додали порт 22, нећете се суочити са проблемима.
root@vultr:~# ufw enable
Command may disrupt existing ssh connections. Proceed with operation (y|n)? y
Firewall is active and enabled on system startup
Када се омогући, затражите статус заштитног зида и видећемо нашу конфигурацију порта.
ufw status
Status: active
To Action From
-- ------ ----
22/tcp ALLOW Anywhere
8080/tcp ALLOW Anywhere
22/tcp (v6) ALLOW Anywhere (v6)
8080/tcp (v6) ALLOW Anywhere (v6)
Корак 2 - Инсталирање Гуацамоле
Инсталирање свих зависности
Пре него што почнемо да инсталирамо, морамо да ажурирамо и надоградимо репо. Са пакетима као што је Tomcat, који је базиран на Јави, постоји сталан ток откривених грешака и њихових повезаних исправки грешака. Обично је добра идеја да ово урадите прво уместо да журите директно у нашу инсталацију.
apt-get update
apt-get -y upgrade
Следеће су све зависности. Гуацамоле има доста њих. (Пуну листу зависности и њихове функције можете пронаћи овде ). Наставимо инсталирањем свих њих.
apt-get -y install build-essential tomcat8 freerdp libcairo2-dev libjpeg-turbo8-dev libpng12-dev libossp-uuid-dev libavcodec-dev libavutil-dev libfreerdp-dev libpango1.0-dev libssh2-1-dev libtelnet-dev libvorbis-dev libwebp-dev mysql-server mysql-client mysql-common mysql-utilities libswscale-dev libvncserver-dev libpulse-dev libssl-dev
Када инсталатер затражи МиСКЛ роот лозинку, наведите је и обавезно је забиљежите. Ову лозинку ћемо касније користити за креирање базе података Гуацамоле.
Преузимање Гуацамоле
Сада када имамо све наше зависности, можемо да наставимо са преузимањем Гуацамоле-а. Сам гвакамоле долази углавном у изворном облику, а не у бинарном облику. Прво ћемо прећи у /tmpфасциклу како бисмо избегли затрпавање других делова диска. Затим преузмите сав изворни код.
Постоје четири изворне/бинарне датотеке за преузимање:
guacamole-0.9.13-incubating.war: Ово је веб апликација. WARДатотека је зиповане веб пакет пружа јединствену сајт хостован на сајту Томцат
guacamole-server-0.9.13-incubating.tar.gz: Ова датотека ће обезбедити позадинску guacdапликацију. Ово ствара токове кроз РДП и ССХ.
guacamole-auth-jdbc-0.9.13-incubating.tar.gz: Користићемо локалну МиСКЛ базу података, тако да нам је потребан повезани JDBCконектор.
mysql-connector-java-5.1.43.tar.gz: Без драјвера базе података ЈДБЦ конектор не ради ништа. Ову датотеку обезбеђује сам МиСКЛ тим.
Напомена: преузимања су решена на најближем серверу .
cd /tmp
wget http://apache.belnet.be/incubator/guacamole/0.9.13-incubating/binary/guacamole-0.9.13-incubating.war
wget http://apache.cu.be/incubator/guacamole/0.9.13-incubating/source/guacamole-server-0.9.13-incubating.tar.gz
wget http://apache.cu.be/incubator/guacamole/0.9.13-incubating/binary/guacamole-auth-jdbc-0.9.13-incubating.tar.gz
wget https://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.43.tar.gz
Када преузмемо све ове датотеке, распакујте tar.gz'с.
tar -xzvf guacamole-server-0.9.13-incubating.tar.gz
tar -xzvf guacamole-auth-jdbc-0.9.13-incubating.tar.gz
tar -xzvf mysql-connector-java-5.1.43.tar.gz
Састављање Гуацамоле
Сада када смо издвојили сав изворни код, направимо неколико guacamoleфасцикли, које ће користити апликација гуацамоле и њене зависности.
mkdir -p /etc/guacamole/lib
mkdir -p /etc/guacamole/extensions
Све је спремно за наше нове Гуацамоле бинарне датотеке. Сада можемо започети процес компилације и инсталације. Пређите на извучену фасциклу Гуацамоле сервера.
cd /tmp/guacamole-server-0.9.13-incubating
Конфигуришите апликацију да креира и init.dдатотеку за касније покретање као сервис.
./configure --with-init-dir=/etc/init.d
Команда треба да се заврши са „да“ на свим библиотекама и протоколима. Ако не, вратите се и проверите команду апт-гет да бисте били сигурни да нисте пропустили ниједан пакет.
------------------------------------------------
guacamole-server version 0.9.13-incubating
------------------------------------------------
Library status:
freerdp ............. yes
pango ............... yes
libavcodec .......... yes
libavutil ........... yes
libssh2 ............. yes
libssl .............. yes
libswscale .......... yes
libtelnet ........... yes
libVNCServer ........ yes
libvorbis ........... yes
libpulse ............ yes
libwebp ............. yes
Protocol support:
RDP ....... yes
SSH ....... yes
Telnet .... yes
VNC ....... yes
Services / tools:
guacd ...... yes
guacenc .... yes
Init scripts: /etc/init.d
Type "make" to compile guacamole-server.
Следеће компајлирајте и инсталирајте Гуцамоле сервер.
make && make install
Када се све ово заврши, покрените ldconfigда бисте поново изградили путању за претрагу за библиотеке које су додате.
ldconfig
Наставите коришћењем systemctlдо подешавања guacd(Гуацамоле Даемон) да бисте покренули при покретању.
systemctl enable guacd
Гуацамоле бинарни фајлови су сада инсталирани. Сада ћемо припремити веб апликацију за Томцат.
Почните тако што ћете преместити warдатотеку у guacamoleфасциклу коју смо управо креирали, када се то уради, креирајте логичку везу у директоријуму томцат која ће указивати на нашу warдатотеку.
cd /tmp
mv guacamole-0.9.13-incubating.war /etc/guacamole/guacamole.war
ln -s /etc/guacamole/guacamole.war /var/lib/tomcat8/webapps/
Затим нам треба мискл конектор и ЈДБЦ. ЈДБЦ драјвер је потребан у extensionsфасцикли, конектор у libфасцикли.
cp mysql-connector-java-5.1.43/mysql-connector-java-5.1.43-bin.jar /etc/guacamole/lib/
cp guacamole-auth-jdbc-0.9.13-incubating/mysql/guacamole-auth-jdbc-mysql-0.9.13-incubating.jar /etc/guacamole/extensions/
Конфигурисање Гуацамоле и Томцат
Once the connector and JDBC are in place, we need to edit the tocamt8 file. This file contains a lot of tomcat8 settings, and in our case we need to add the GUACAMOLE_HOME variable at the end of the file.
nano /etc/default/tomcat8
Append with the following.
GUACAMOLE_HOME=/etc/guacamole
Creating the database
Next up is creating the database. Guacamole stores its connection configuration in a database, not inside a file.
Login with the root password you used during the installation.
mysql -u root -p
The first step is to create a database called 'guacamole_db'.
create database guacamole_db;
Then run the create user command. This will create a user with a password mysupersecretpassword, this user will only be able to connect from localhost.
create user 'guacamole_user'@'localhost' identified by "mysupersecretpassword";
Grant CRUD operations to this user for the database guacamole_db.
GRANT SELECT,INSERT,UPDATE,DELETE ON guacamole_db.* TO 'guacamole_user'@'localhost';
Flush privileges and exit the shell.
flush privileges;
exit
Finish up by adding the Guacamole schema to our newly created database.
cat /tmp/guacamole-auth-jdbc-0.9.13-incubating/mysql/schema/*.sql | mysql -u root -p guacamole_db
Once this is done, we need to edit the guacamole.properties file. This file contains our recently created MySQL server configuration.
nano /etc/guacamole/guacamole.properties
Append the MySQL connection details and credentials.
mysql-hostname: localhost
mysql-port: 3306
mysql-database: guacamole_db
mysql-username: guacamole_user
mysql-password: mysupersecretpassword
Finish up by creating a symbolic link to the tomcat share folder, as this is where the WAR file will search these properties.
ln -s /etc/guacamole /usr/share/tomcat8/.guacamole
Testing the setup
End by restarting the tomcat8 server and start the guacd server daemon.
service tomcat8 restart
service guacd start
You can verify by using the status command.
service tomcat8 status
service guacd status
Now you can browse to your VPS on port 8080
http://<yourpublicip>:8080/guacamole/
Use the username guacadmin and the same password guacadmin. This will grant you access to an empty Guacamole server.
Click in the top right corner on your username guacadmin and select Settings. Once you are in the settings page go to the Users tab and select the user guacadmin.
Now change your password to something else or create a new admin user and delete the default guacadmin one.
Step 3 - Fine tuning and cleanup
These are the final steps: cleaning up after you are done.
Delete the downloaded source code and binaries from the /tmp folder.
rm -rf /tmp/guacamole-*
rm -rf /tmp/mysql-connector-java-*
Also, make the Guacamole web application the default one. In the tomcat ecosystem the application that gets the ROOT folder is the one that is started by default when you access the website.
Delete the old ROOT placeholder.
rm -rf /var/lib/tomcat8/webapps/ROOT
And make a symbolic link for the guacamole server to be the ROOT one.
ln -s /var/lib/tomcat8/webapps/guacamole /var/lib/tomcat8/webapps/ROOT
This requires a tomcat restart.
service tomcat8 restart
Step 4 (option A) - Running on HTTP only
- If you are not going to use Let's Encrypt certificates and not use a DNS, execute the actions in this step and afterwards go directly to Step 6. - Option A
- If you want to create a more secure site and you have a DNS ready, you can skip this and go straight to option B (Step 5).
Edit the tomcat8/server.xml file and change the connector port.
nano /etc/tomcat8/server.xml
Search for the Connector port.
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
URIEncoding="UTF-8"
redirectPort="8443" />
And replace 8080 with 80.
By default, tomcat doesn't allow the binding of ports below 1024. To enable this we need to tell tomcat8 to create authenticated binds.
Edit the default file of tomcat8 and uncomment the AUTHBIND line and use the option yes
nano /etc/default/tomcat8
AUTHBIND=yes
Once this is done, intall authbind.
apt-get install authbind
Configure it so that port 80 can be claimed by tomcat8.
touch /etc/authbind/byport/80
chmod 500 /etc/authbind/byport/80
chown tomcat8 /etc/authbind/byport/80
Allow port 80 through the firewall and delete the rule for 8080.
ufw allow 80/tcp
ufw delete allow 8080/tcp
Restart tomcat.
service tomcat8 restart
That's it, now Guacamole should be running on port 80.
Step 5 (option B) - Setting up Nginx
Installation and configuration of Nginx
Tomcat really isn't one of the best and most robust applications to use with certbot. Luckily Nginx is. We will just to proxy tomcat to Nginx. It uses the out-of-the-box functionality of certbot at the cost of sacrificing a little bit of RAM.
apt-get install nginx
Once installed, edit the default configuration.
nano /etc/nginx/sites-available/default
Delete all example configurations and add the following configuration.
server {
listen 0.0.0.0:80;
proxy_request_buffering off;
proxy_buffering off;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
}
}
This will create a proxy for the website running at 8080. Restart Nginx, and enable it at boot.
systemctl restart nginx
systemctl enable nginx
Check if everything is working.
systemctl status nginx
Disable the testing port 8080 and allow traffic on port 80.
ufw allow 80/tcp
ufw delete allow 8080/tcp
Installing Let's Encrypt
Before we can use certbot, we need to add the correct ppa to the system containing our certbot packages.
add-apt-repository ppa:certbot/certbot
Press "ENTER" to accept the configuration change.
Update apt to gather the new packages.
apt-get update
Finally, install the Nginx module for assigning the certificates.
apt-get -y install python-certbot-nginx
Configure Nginx to use certificates
Configure the firewall to allow HTTPS.
ufw allow 443/tcp
Before we can request new certificates, we need a DNS name.
nano /etc/nginx/sites-available/default
Add the following server_name setting.
server_name rdp.example.com;
Change the configuration to reflect this new setting.
server {
server_name rdp.example.com;
listen 0.0.0.0:80;
proxy_request_buffering off;
proxy_buffering off;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
}
}
Check if all is working and restart Nginx.
nginx -t
service nginx restart
Now request a certificate with certbot.
certbot --nginx -d rdp.example.com
Наведите своју е-пошту и сложите се са питањима која поставља инсталатер. (Можете безбедно да изаберете " No" да делите своју е-пошту.) Цертбот ће аутоматски питати шта треба да уради са HTTPS. Користићемо опцију 2: redirect to HTTPS.
Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
-------------------------------------------------------------------------------
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
-------------------------------------------------------------------------------
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2
Последња ствар коју ћемо урадити је ажурирање DHпараметара. Они су, подразумевано, мало слаби за стандарде 2017.
Направите неке нове.
openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048
Затим их додајте на подразумевану локацију у Нгинк-у.
nano /etc/nginx/sites-available/default
Додајте их у конфигурацију сервера.
server {
server_name rdp.example.com;
listen 0.0.0.0:80;
ssl_dhparam /etc/ssl/certs/dhparam.pem;
proxy_request_buffering off;
proxy_buffering off;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
}
}
Проверите грешке.
nginx -t
Примените промене поновним покретањем сервера.
service nginx restart
Очистите старо 8080правило
ufw delete allow 8080/tcp
Напомена: ако добијете „502 Бад Гатеваи“, мораћете поново да покренете томцат8 .
service tomcat8 restart
Аутоматско обнављање сертификата
Лет'с Енцрипт сертификати захтевају обнову. Можемо креирати црон посао за ово. Започните уређивањем crontab.
crontab -e
Додајте следећи ред.
00 2 * * * /usr/bin/certbot renew --quiet
Ово ће проверити у 2:00 ујутру да ли неки сертификати захтевају обнову и обновиће их ако треба.
Корак 6 - Тестирајте све
Идите на свој Гуацамоле сервер ( http://<ip>/или https://rdp.example.com)).
За овај тест ће вам требати још две инстанце: једна Линук ВМ и друга Виндовс Сервер 2012 Р2 са приватном ИП која је омогућена на обе.
Додавање Виндовс РДП везе
Кликните на " username" у горњем десном углу и идите на " Settings". Затим идите на " Connections" и изаберите " New Connection".
Попуните следећа подешавања (друге можете оставити подразумеване).
Name: Windows Server 2012 R2
Location: ROOT
Protocol: RDP
Maximum number of connections: 1
Maximum number of connections per user: 1
Parameters > Hostname: 10.99.0.12
Parameters > Port: 3389
Username: Administrator
Password: <password> (provided by Vultr)
Security mode: Any
Ignore server certificate: <checked>
Притисните " save" и вратите се на почетни екран. Сада можете да кликнете на Windows Server 2012 R2везу " " и она ће РДП на ову машину.
Додавање Линук ССХ везе
Притисните " Ctrl+Shift+Alt". Ово ће искочити мени са стране. Овде можете прекинути везу или извршити друге административне задатке за Гуацамоле.
Кликните usernameна врх у менију и идите на " Settings". Затим идите на картицу " Connections" и изаберите " New Connection".
Попуните следећа подешавања (друге можете оставити подразумеване).
Name: Linux
Location: ROOT
Protocol: SSH
Maximum number of connections: 5
Maximum number of connections per user: 2
Parameters > Hostname: 10.99.0.11
Parameters > Port: 22
Username: root
Password: <password> (provided by Vultr)
Притисните " save" и вратите се на почетни екран. Сада можете да кликнете на ову новостворену везу и да будете повезани са својим Линук сервером преко ССХ-а.
Закључак
Сада имате веб РДП/ССХ ХТМЛ5 мрежни пролаз. Сада можете заштитити јавни РДП и ССХ приступ ваше платформе и приступити свом окружењу из било ког модерног претраживача. За више информација о томе шта Гуацамоле може да понуди, постоји одличан видео који приказује све могућности платформе овде .