Uvod
Korak 1 - Priprema sustava
Korak 2 - Instaliranje Guacamolea
Korak 3 - Fino podešavanje i čišćenje
Korak 4 (opcija A) - Izvođenje samo na HTTP-u
Korak 5 (opcija B) - Postavljanje Nginxa
Korak 6 - Testirajte sve
Zaključak
Uvod
Cilj ovog tutoriala je riješiti se javnih SSH i javnih RDP veza. Stavljajući sve ovo iza vrlo prikladnog HTML5 klijenta, možemo dodati sloj sigurnosti za pristup našem oblaku.
Guacamole također bilježi svaki daljinski pristup, tako da je neovlašteni pristup mnogo lakše ući u trag.
Napomena: Za Let's encrypt (opcija B) trebamo naziv domene. Ako nemate, možete preskočiti ovaj korak i samo izvršiti Opcija A .
Korak 1 - Priprema sustava
Započnite okretanjem VPS-a u željenoj Vultr zoni. 1024 MBVPS će biti dovoljno, kao guacamole nije tako zahtjevna.
Omogućavanje privatnog IP-a
Započnite tako što ćete omogućiti privatnu mrežu na VPS-u. To je dobro dokumentirano ovdje
Priprema vatrozida
Prvo malo učvrstimo sliku. I provjerimo je li ufwomogućena slika koja je dodijeljena .
root@vultr:~# ufw status
Status: inactive
Prema zadanim postavkama je onemogućen, pa ćemo morati dodati nekoliko pravila.
- Pravilo 1: ssh: TCP port 22
- Pravilo 2: http: TCP port 8080 (privremeno pravilo testiranja za Guacamole)
Počnimo s konfiguriranjem ovih portova.
ufw allow 22/tcp
ufw allow 8080/tcp
Zatim omogućite vatrozid.
ufw enable
Ne brinite ako dobijete upozorenje. Ako ste dodali port 22, nećete se suočiti s problemima.
root@vultr:~# ufw enable
Command may disrupt existing ssh connections. Proceed with operation (y|n)? y
Firewall is active and enabled on system startup
Nakon što je omogućeno, zatražite status vatrozida i vidjet ćemo našu konfiguraciju porta.
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)
Korak 2 - Instaliranje Guacamolea
Instaliranje svih ovisnosti
Prije nego što počnemo instalirati moramo ažurirati i nadograditi repo. S paketima kao što je Tomcat, koji se temelji na Javi, postoji stalan tok otkrivenih bugova i s njima povezanih ispravaka grešaka. Obično je dobra ideja to učiniti prvo umjesto da žurimo izravno u našu instalaciju.
apt-get update
apt-get -y upgrade
Sljedeće su sve ovisnosti. Guacamole ih ima dosta. (Cijeli popis ovisnosti i njihove funkcije možete pronaći ovdje ). Nastavimo instaliranjem svih njih.
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
Kada instalater zatraži MySQL root lozinku, navedite je i svakako je zabilježite. Kasnije ćemo koristiti ovu lozinku za izradu baze podataka Guacamole.
Preuzimanje Guacamolea
Sada kada imamo sve naše ovisnosti, možemo nastaviti s preuzimanjem Guacamolea. Sam guacamole dolazi uglavnom u izvornom obliku, a ne u binarnom obliku. Prvo ćemo prijeći u /tmpmapu kako bismo izbjegli zatrpavanje drugih dijelova diska. Zatim preuzmite sav izvorni kod.
Postoje četiri izvorne/binarne datoteke za preuzimanje:
guacamole-0.9.13-incubating.war: Ovo je web aplikacija. WARDatoteka je komprimirana web paket pruža jednu web stranicu na web-lokaciji Tomcat
guacamole-server-0.9.13-incubating.tar.gz: Ova datoteka će pružiti pozadinsku guacdaplikaciju. To stvara streamove kroz RDP i SSH.
guacamole-auth-jdbc-0.9.13-incubating.tar.gz: Koristit ćemo lokalnu MySQL bazu podataka, tako da nam je potreban pridruženi JDBCkonektor.
mysql-connector-java-5.1.43.tar.gz: Bez drajvera baze podataka JDBC konektor ne radi ništa. Ovu datoteku osigurava sam MySQL tim.
Napomena: preuzimanja su riješena na najbliži poslužitelj .
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
Nakon što preuzmemo sve ove datoteke, raspakirajte tar.gz's.
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
Sastavljanje Guacamolea
Sada kada smo izdvojili sav izvorni kod, napravimo nekoliko guacamolemapa, koje će koristiti aplikacija guacamole i njezine ovisnosti.
mkdir -p /etc/guacamole/lib
mkdir -p /etc/guacamole/extensions
Sve je spremno za naše nove Guacamole binarne datoteke. Sada možemo započeti proces kompilacije i instalacije. Prijeđite na ekstrahiranu mapu poslužitelja Guacamole.
cd /tmp/guacamole-server-0.9.13-incubating
Konfigurirajte aplikaciju da također stvori init.ddatoteku za kasnije pokretanje kao uslugu.
./configure --with-init-dir=/etc/init.d
Naredba bi trebala završiti s "da" na svim knjižnicama i protokolima. Ako ne, vratite se i provjerite naredbu apt-get kako biste bili sigurni da niste propustili nijedan paket.
------------------------------------------------
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.
Sljedeće kompajlirajte i instalirajte Gucamole poslužitelj.
make && make install
Nakon što je sve to učinjeno, pokrenite ldconfigkako biste ponovno izgradili put pretraživanja za knjižnice koje su dodane.
ldconfig
Nastavite korištenjem systemctlza postavljanje guacd(Guacamole Daemon) za pokretanje pri pokretanju.
systemctl enable guacd
Guacamole binarne datoteke su sada instalirane. Sada ćemo pripremiti web aplikaciju za Tomcat.
Započnite premještanjem wardatoteke u guacamolemapu koju smo upravo stvorili, nakon što je to učinjeno, stvorite logičku vezu u direktoriju tomcat koja pokazuje na našu wardatoteku.
cd /tmp
mv guacamole-0.9.13-incubating.war /etc/guacamole/guacamole.war
ln -s /etc/guacamole/guacamole.war /var/lib/tomcat8/webapps/
Zatim trebamo mysql konektor i JDBC. JDBC drajver je potreban u extensionsmapi, konektor u libmapi.
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/
Konfiguriranje Guacamolea i Tomcata
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
Navedite svoju e-poštu i složite se s pitanjima koja postavlja instalater. (Možete sigurno odabrati " No" za dijeljenje svoje e-pošte.) Certbot će automatski pitati što treba učiniti s HTTPS. Koristit ćemo opciju 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
Posljednje što ćemo učiniti je ažuriranje DHparametara. Oni su prema zadanim postavkama malo slabi za standarde 2017.
Stvorite neke nove.
openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048
Zatim ih dodajte na zadanu stranicu u Nginxu.
nano /etc/nginx/sites-available/default
Dodajte ih u konfiguraciju poslužitelja.
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;
}
}
Provjerite ima li pogrešaka.
nginx -t
Primijenite promjene ponovnim pokretanjem poslužitelja.
service nginx restart
Očistite staro 8080pravilo
ufw delete allow 8080/tcp
Napomena: ako dobijete "502 Bad Gateway", morat ćete ponovno pokrenuti tomcat8 .
service tomcat8 restart
Automatsko obnavljanje certifikata
Certifikati Let's Encrypt zahtijevaju obnovu. Za ovo možemo stvoriti cron posao. Započnite s uređivanjem crontab.
crontab -e
Dodajte sljedeći redak.
00 2 * * * /usr/bin/certbot renew --quiet
Time će se u 2:00 ujutro provjeriti jesu li neki certifikati zahtijevali obnovu i obnovit će ih ako je potrebno.
Korak 6 - Testirajte sve
Idite na svoj poslužitelj Guacamole ( http://<ip>/ili https://rdp.example.com)).
Za ovaj test trebat će vam još dvije instance: jedan Linux VM i drugi Windows Server 2012 R2 s omogućenim privatnim IP-om na obje.
Dodavanje Windows RDP veze
Kliknite " username" u gornjem desnom kutu i idite na " Settings". Zatim idite na " Connections" i odaberite " New Connection".
Ispunite sljedeće postavke (ostale možete ostaviti zadane).
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>
Pritisnite " save" i vratite se na početni zaslon. Sada možete kliknuti na vezu " Windows Server 2012 R2" i ona će RDP na ovaj stroj.
Dodavanje Linux SSH veze
Pritisnite " Ctrl+Shift+Alt". Ovo će iskočiti izbornik sa strane. Ovdje možete prekinuti vezu ili izvršiti druge administrativne zadatke za Guacamole.
Kliknite usernamena vrh u izborniku i idite na " Settings". Zatim idite na karticu " Connections" i odaberite " New Connection".
Ispunite sljedeće postavke (ostale možete ostaviti zadane).
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)
Pritisnite " save" i vratite se na početni zaslon. Sada možete kliknuti ovu novostvorenu vezu i biti spojeni na svoj Linux poslužitelj putem SSH-a.
Zaključak
Sada imate web RDP/SSH HTML5 pristupnik. Sada možete postaviti vatrozid na javni RDP i SSH pristup svoje platforme i pristupiti svom okruženju iz bilo kojeg modernog preglednika. Za više informacija o tome što guacamole može ponuditi, postoji velika video prikazuje sve possiblities platforme ovdje .