Son güncelleme tarihi 5 Eylül 2022
Kim istemez ki 🙂
Az masraflı Cloud VM, şaka değil mümkün ama biraz dolambaçlı. Dolar kurunun alıp başını gittiği bu günlerde test için Cloud hizmeti sunan bir firmadan giriş seviye bir VM başlatsanız bile aylık hesaba vurduğunuz zaman masraflar, aldığınız hizmet ile kıyasladığınızda canınızı sıkabilecek düzeyde olabiliyor…
Peki çözümü var mı?
Evet, şahsen kullandığım bir yöntem var ve bu yazımda onu açıklayacağım. Linux sistem yöneticisi arkadaşlardan daha önce kullanmayan varsa da faydalanacaklarını ümid ediyorum. SSH kullanarak yerelde statik ip adresine ihtiyaç olmadan yani, CGNAT kullanan ev internetimizle bile Web Hosting sınıfındaki neredeyse tüm hizmetleri yerel bilgisayarımızdaki sanallaştırma altyapısıyla sağlayabiliriz.
İhtiyaç listesine bir göz atalım.
- Cloud Sanal Makine, Cloud hizmeti veren herhangi bir firmadan alınan VM (giriş seviye olabilir) mesela ben genellikle DigitalOcean üzerinden bu hizmeti alıyorum, kaydolmak isteyen varsa bu link üzerinden kaydolarak 60 günlük kullanıma sahip $100 değerinde ücretsiz kullanım hakkı elde edebilirsiniz.
- Sanallaştırma Sistemi bilgisi yerel sistemimizdeki VM ile asıl işlemleri yapacağımız için gerekli.
- Temel Server kurulumu bilgisi, network protokollerini yüzeysel olarak biliyor olsanız bile yeterli, ayrıca ssh, web, ftp, dns, veritabanı, mail, nfs, v.b. sunucuları yapılandırabiliyor olmalısınız. Yerel VM üzerine kuracağız doğal olarak.
- Web Proxy bilgisi
- Upload Bant Genişliği 10Mbit altında olmayan ev interneti, ne kadar fazla o kadar iyi.
- SSH kullanım bilgisi, ve port redirection, ssh key pair, ssh config, bu yazımın merkezinde tam olarak bu başlık var.
- systemd bilgisi kurulumumuzun otonom şekilde çalışması için sistem servislerini oluşturmak gerekiyor.
Dezavantajları / Avantajları
- Kişisel bilgisayarınız kapalıysa sunulacak birşey yok demektir.
- Yerel internetiniz kesildiyse sunulacak birşey yok demektir.
- Diğer taraftan 1/10 masrafla sunucu ayağa kaldırabilirsiniz.
- Konsol, Backup, Snapshot elinizin altında olur, yönetim kolaylaşır.
- Veri Gizliliğiniz elinizin altında olur. (Cloud VM sadece relay vazifesi göreceğinden)
- Testlerinizi çoook daha ucuza, hızlı şekilde gerçekleştirmiş olursunuz.
1vCPU, 2GB ram, 25GB disk için aylık ödediğimiz para $6 (~90TL) peki GitLab-CE kurup kullanmak istersek, sistemin adam akıllı çalışması için minimum 4vCPU, 8GB ram, 100GB disk alanına ihtiyacımız var bu özelliklere sahip VM’i hizmet sağlayıcıdan almak istersek aylık $48 (~720TL) gibi bir masraf karşımıza çıkıyor. Eğer kişisel bilgisayarımızda bu kaynak varsa $6 VM ile GitLab DevOps sunucusunu kurup kullanabiliriz.

İşlem adımları;
- Cloud VM oluşturalım.
- DNS ayarlarımızı yapalım, domain/subdomain yeni oluşturduğumuz VM’i göstersin.
- Yerel bilgisayarımızda yüksek kapasiteli bir VM oluşturalım.
- Cloud VM içerisine ihtiyaç duyduğumuz uygulamaları kuralım, yapılandıralım.
- SSH port redirection ile Yerel VM üzerindeki bir uygulamaya, Cloud VM üzerinden nasıl erişilebileceğine bakalım.
- SSH port redirection işlemini systemd unit file kullanarak otomatize edelim, sistem servisi haline getirelim.
Bu adımları attığımızda yerel bilgisayarımızda kurduğumuz VM üzerindeki sunucu uygulamaları aynen Digital Ocean tarafındaki VM üzerinden erişilebilecektir.
1. Cloud VM Oluşturalım
En basit adımlarımızdan birisi, yapılandırmayı seç, hostname yaz, oluştur butonuna bas bitti.

2. DNS ayarlarımızı yapalım
Bu kısım sizin tarafınızda, bir alan adına sahip olmalısınız, Cloud hizmeti veren firmalar genellikle ücretsiz DNS hizmeti de vermekte, yönergeleri izleyin. Benim gibi kendi DNS sunucunuz varsa eğer A kaydı ekleme işlemini biliyorsunuz demektir, elinizdeki domainlerden birtanesine A kaydı ekleyin ve yeni oluşturduğumuz Cloud VM ip adresini göstersin. AAAA kaydı da ekleyebilirsiniz ipv6 adresini gösterebilir (opsiyonel) yerel internetim ipv6 desteklemediğinden bu kısmı uygulamaya dökemeyeceğim.

ysn.app alan adı üzerinde vcs.ysn.app alt alanadını yeni Cloud VM’i gösterecek şekilde yapılandırdım.
Cloudflare DNS’i sunucumun A kaydını 2dk içerisinde gördü, yani işlem yapmaya başlayabiliriz.

3. Yerel bilgisayarımızda yüksek kapasiteli bir VM oluşturalım.
Bu kısmı size bırakıyorum, Yerel VM için hangi sanallaştırma altyapısını kullanırsanız kullanın sonuç değişmeyecektir, makineyi ister veritabanı sunucusu olarak kurun, ister web hosting makinesi olarak kurun, ister benim yaptığım gibi GitLab-CE kurun size kalmış, yüksek kapasite ihtiyacı olan herhangi bir uygulama olması burada toplanmamızın asıl amacı 🙂 VM oluşturmayıp kişisel bilgisayarınızdaki portları da Cloud VM tarafına paslayabilirsiniz, sizin tercihiniz.

4. Cloud VM içerisine ihtiyaç duyduğumuz uygulamaları kuralım, yapılandıralım.
Temelde ssh uygulamamız tüm ihtiyacımızı karşılıyor, hali hazırda varsayılan kurulum ssh publickey kısıtlamasına sahip, sadece ssh port 22 yerine Cloud VM 2222, Yerel VM 22 olacak şekilde bir değişiklik yapacağım. İlaveten ufw firewall kurup temel uygulamalarımıza izin verdiğimizde genel manada işimiz tamamdır.
yasin@uxn-workstation:~$ ssh vcs.ysn.app # root olarak sed -i 's/#Port 22/Port 2222/g' /etc/ssh/sshd_config exit logout Connection to vcs.ysn.app closed. yasin@uxn-workstation:~$ ssh vcs.ysn.app "systemctl restart sshd" yasin@uxn-workstation:~$ ssh vcs.ysn.app ssh: connect to host vcs.ysn.app port 22: Network is unreachable
Yukarıda farketmişsinizdir ssh vcs.ysn.app diyerek ne kullanıcı adı ne parola ne başka bir bilgi vermeden doğrudan sunucuma erişiyorum, bunu sağlayan yapı SSH keypair ve SSH config dosyası, varsayılan ~/.ssh/config dosyasıdır, ancak isteğe bağlı farklı bir dosya içerisinden de özellikler okutulabilir.
# keep alive all hosts connections Host * ServerAliveInterval 60 ServerAliveCountMax 3 Host ysnapp HostName vcs.ysn.app User root Port 2222 IdentityFile ~/.ssh/parolasiz_yeni
Yukarıdaki örnek SSH yapılandırması ~/.ssh/config içerisinde yer alıyor, farklı bir yere ssh-con.config olarak kaydedip kullanmak istersem komut şu şekilde işleyecek.
ssh -F ~/ssh-con.config ysnapp

SSH uygulaması ve detaylı açıklamaları başka bir yazının konusu o sebepten burada bırakıyorum.
UFW firewall yapılandırmasını olabildiğince basit tutacağım,
apt install ufw ufw default deny incoming ufw default allow outgoing ufw default allow routed ufw allow ssh ufw allow http ufw allow https ufw allow 2222/tcp comment 'SSH Port' ufw enable
Buraya kadar Yerel ve Cloud tarafındaki ayarlamaları bitirmiş olduk, an itibariyle;
- Cloud VM bir domain ile erişilebiliyor olmalı.
- Yerel VM ile Cloud VM arasında ssh keypair kullanarak ssh bağlantısı kurulabiliyor olmalı.
- Yerel VM üzerinde yayınlamak istediğimiz uygulamalar çalışıyor olmalı.
- Sıraladığım bu 3 madde için internette zibilyontane how-to var hali hazırda, ben karşılaştığım probleme getirdiğim çözümü paylaşıyorum, yeri gelirse bu maddeler için de örnek hazırlarım. Mesela şurada ssh keypair oluşturma ile ilgili bir yazı yazmışım zamanında. Özü aynı, PC üzerinde ssh-copy-id kullansak keyleri aktarmak daha basit olur.
5. SSH port redirection
Hızlı bir giriş yaparak yerel bilgisayarımdaki mysql veri tabanı ve http web sunucusunu yönlendirelim…
MySql 3306/tcp
HTTP 80/tcp
ssh -NT -R 80:0.0.0.0:80 vcs.ysn.app ssh -NT -R 3306:0.0.0.0:3306 vcs.ysn.app
Yukarıdaki 2 komutu 2 ayrı terminalde açalım ve ne olduğuna bakalım.
yasin@uxn-workstation:~$ ssh vcs.ysn.app netstat -tlpn4 Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 3727/sshd: root tcp 0 0 0.0.0.0:2222 0.0.0.0:* LISTEN 2459/sshd: /usr/sbi tcp 0 0 127.0.0.1:80 0.0.0.0:* LISTEN 3720/sshd: root
Sunucularımızın local 127.0.0.1 olarak değilde, tüm networke 0.0.0.0 yayın yapmasını istiyorsak Cloud VM üzerinde;
sed -i 's/#GatewayPorts no/GatewayPorts yes/g' /etc/ssh/sshd_config systemctl restart sshd
restart dedikten sonra yukarıdaki bağlantıları yeniden başlatmayı unutmayın 🙂
netstat -tlpn4 Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 3790/sshd: root tcp 0 0 0.0.0.0:2222 0.0.0.0:* LISTEN 3780/sshd: /usr/sbi tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 3783/sshd: root
artık istediğim gibi çalışıyor.
http://vcs.ysn.app adresine gittiğimde karşıma yerel bilgisayarımın web server varsayılan dizini çıkıyor. HTTP redirection başarılı.

MYSQL redirection ne alemde ona bakalım. Normalde dışarıdan 3306 portuna erişim kapalı, geçici olarak ufw allow 3306 dedim ve test için erişime izin verdim.

Bu şekilde redirect yapabileceğimiz bir başka uygulama ise SSH, yukarıda vcs.ysn.app makinesinin ssh portunu 2222 çevirme sebebim tam olarak bundan.
ssh -NT -R 22:0.0.0.0:22 vcs.ysn.app
Şu anda vcs.ysn.app makinesine Web Sunucu, Mysql Sunucu, SSH sunucu bağlantısı yapılmaya kalkıldığında doğrudan yereldeki sistemime yönlendirme işlemi gerçekleşiyor. Bunun gibi neleri aktarabiliriz sorusuna ise “TCP protokolü ile iletişim kuran neredeyse tüm uygulamaları” şeklinde cevaplarsam yalnış olmaz sanırım.. Aşağıdaki tabloda portlar ve o portlar üzerinde kullanılan uygulamaları bulabilirsiniz, ayıklamaya uğraşmadım TCP olanları bu yöntem ile redirect yapabiliriz.
PORT | PROTOCOL | APPLICATION | STATUS |
---|---|---|---|
0 | TCP, UDP | Reserved; do not use (but is a permissible source port value if the sending process does not expect messages in response) | Offical |
1 | TCP, UDP | TCPMUX | Offical |
5 | TCP, UDP | RJE (Remote Job Entry) | Offical |
7 | TCP, UDP | ECHO protocol | Offical |
9 | TCP, UDP | DISCARD protocol | Offical |
11 | TCP, UDP | SYSTAT protocol | Offical |
13 | TCP, UDP | DAYTIME protocol | Offical |
17 | TCP, UDP | QOTD (Quote of the Day) protocol | Offical |
18 | TCP, UDP | Message Send Protocol | Offical |
19 | TCP, UDP | CHARGEN (Character Generator) protocol | Offical |
20 | TCP | FTP Protocol (data) - port for transferring FTP data | Offical |
21 | TCP | FTP Protocol (control) - port for FTP commands and flow control | Offical |
22 | TCP, UDP | SSH (Secure Shell) - used for secure logins, file transfers (scp, sftp) and port forwarding | Offical |
23 | TCP, UDP | Telnet protocol - unencrypted text communication, remote login service | Offical |
25 | TCP, UDP | SMTP (Simple Mail Transport Protocol) - used for email routing between email servers | Offical |
26 | TCP, UDP | RSFTP - A simple FTP-like protocol | Unoffical |
35 | TCP, UDP | QMS Magicolor 2 printer | Unoffical |
37 | TCP, UDP | TIME protocol | Offical |
38 | TCP, UDP | Route Access Protocol | Offical |
39 | TCP, UDP | Resource Location Protocol | Offical |
41 | TCP, UDP | Graphics | Offical |
42 | TCP, UDP | Host Name Server/WINS Replications | Offical |
43 | TCP | WHOIS protocol | Offical |
49 | TCP, UDP | TACACS Login Host protocol | Offical |
53 | TCP, UDP | DNS (Domain Name System) | Offical |
57 | TCP | MTP, Mail Transfer Protocol | Offical |
67 | UDP | BOOTP (BootStrap Protocol) server; also used by DHCP (Dynamic Host Configuration Protocol) | Offical |
68 | UDP | BOOTP (BootStrap Protocol) client; also used by DHCP (Dynamic Host Configuration Protocol) | Offical |
69 | UDP | TFTP (Trivial File Transfer Protocol) | Offical |
70 | TCP | Gopher protocol | Offical |
79 | TCP | Finger protocol | Offical |
80 | TCP | HTTP (HyperText Transfer Protocol) - used for transferring web pages | Offical |
81 | TCP | Torpark - Onion routing ORport | Unoffical |
82 | UDP | Torpark - Control Port | Unoffical |
88 | TCP | Kerberos - authenticating agent | Offical |
101 | TCP | HOSTNAME | |
102 | TCP | ISO-TSAP protocol/Microsoft Exchange | |
107 | TCP | Remote Telnet Service | |
109 | TCP | POP, Post Office Protocol, version 2 | |
110 | TCP | POP3 (Post Office Protocol version 3) - used for retrieving emails | Offical |
111 | TCP, UDP | SUNRPC protocol | |
113 | TCP | Ident - old server identification system, still used by IRC servers to identify its users | Offical |
115 | TCP | SFTP, Simple File Transfer Protocol | |
117 | TCP | UUCP-PATH | |
118 | TCP, UDP | SQL Services | Offical |
119 | TCP | NNTP (Network News Transfer Protocol) - used for retrieving newsgroups messages | Offical |
123 | UDP | NTP (Network Time Protocol) - used for time synchronization | Offical |
135 | TCP, UDP | EPMAP / Microsoft RPC Locator Service | Offical |
137 | TCP, UDP | NetBIOS NetBIOS Name Service | Offical |
138 | TCP, UDP | NetBIOS NetBIOS Datagram Service | Offical |
139 | TCP, UDP | NetBIOS NetBIOS Session Service | Offical |
143 | TCP, UDP | IMAP4 (Internet Message Access Protocol 4) - used for retrieving emails | Offical |
152 | TCP, UDP | BFTP, Background File Transfer Program | |
153 | TCP, UDP | SGMP, Simple Gateway Monitoring Protocol | |
156 | TCP, UDP | SQL Service | Offical |
157 | TCP, UDP | KNET VM Command Message Protocol | |
158 | TCP, UDP | DMSP, Distributed Mail Service Protocol | |
159 | TCP, UDP | NSS-Routing | |
160 | TCP, UDP | SGMP-TRAPS | |
161 | TCP, UDP | SNMP (Simple Network Management Protocol) | Offical |
162 | TCP, UDP | SNMPTRAP | Offical |
170 | TCP | Print-srv | |
179 | TCP | BGP (Border Gateway Protocol) - an exterior gateway routing protocol that enables groups of routers to share routing information to ensure efficient and loop-free routes can be established. BGP is commonly used within and between ISPs. | Offical |
190 | TCP, UDP | Gateway Access Control Protocol (GACP) | |
191 | TCP, UDP | Prospero Directory Service | |
192 | TCP, UDP | OSU Network Monitoring System, Apple AirPort Base Station PPP status or discovery, AirPort Admin Utility or Express Assistant | |
192 | TCP. UDP | SRMP (Spider Remote Monitoring Protocol) | |
194 | TCP | IRC (Internet Relay Chat) | Offical |
201 | TCP, UDP | AppleTalk Routing Maintenance | |
209 | TCP, UDP | The Quick Mail Transfer Protocol | |
213 | TCP, UDP | IPX | Offical |
218 | TCP, UDP | MPP, Message Posting Protocol | |
220 | TCP, UDP | IMAP, Interactive Mail AccessProtocol, version 3 | |
259 | TCP, UDP | ESRO, Efficient Short Remote Operations | |
264 | TCP, UDP | BGMP, Border Gateway Multicast Protocol | |
311 | TCP | Apple Server-Admin-Tool, Workgroup-Manager-Tool | |
318 | TCP, UDP | TSP, Time Stamp Protocol | |
323 | TCP, UDP | IMMP, Internet Message Mapping Protocol | |
383 | TCP, UDP | HP OpenView HTTPs Operations Agent | |
366 | TCP, UDP | SMTP, Simple Mail Transfer Protocol. On-Demand Mail Relay (ODMR) | |
369 | TCP, UDP | Rpc2portmap | Offical |
371 | TCP, UDP | ClearCase albd | Offical |
384 | TCP, UDP | A Remote Network Server System | |
387 | TCP, UDP | AURP, AppleTalk Update-Based Routing Protocol | |
389 | TCP, UDP | LDAP (Lightweight Directory Access Protocol) | Offical |
401 | TCP, UDP | UPS Uninterruptible Power Supply Offical | |
411 | TCP | Direct Connect Hub port | Unoffical |
427 | TCP, UDP | SLP (Service Location Protocol) | Offical |
443 | TCP | HTTPS - HTTP Protocol over TLS/SSL (used for transferring web pages securely using encryption) | Offical |
444 | TCP, UDP | SNPP, Simple Network Paging Protocol | |
445 | TCP | Microsoft-DS (Active Directory, Windows shares, Sasser worm, Agobot, Zobotworm) | Offical |
445 | UDP | Microsoft-DS SMB file sharing | Offical |
464 | TCP, UDP | Kerberos Change/Set password | Offical |
465 | TCP | SMTP over SSL - CONFLICT with registered Cisco protocol | Conflict |
500 | TCP, UDP | ISAKMP, IKE-Internet Key Exchange | Offical |
512 | TCP | , Remote Process Execution | |
512 | UDP | at, together with biff: notifies users of new c.q. yet unread e-mail | |
513 | TCP | Login | |
513 | UDP | Who | |
514 | TCP | rsh protocol - used to execute non-interactive commandline commands on a remote system and see the screen return | |
514 | UDP | syslog protocol - used for system logging | Offical |
515 | TCP | Line Printer Daemon protocol - used in LPD printer servers | |
517 | TCP | Talk | |
518 | UDP | NTalk | |
520 | TCP | efs | |
520 | UDP | Routing - RIP | Offical |
513 | UDP | Router | |
524 | TCP, UDP | NCP (NetWare Core Protocol) is used for a variety things such as access to primary NetWare server resources, Time Synchronization, etc. | Offical |
525 | UDP | Timed, Timeserver | |
530 | TCP, UDP | RPC | Offical |
531 | TCP, UDP | AOL Instant Messenger, IRC | |
532 | TCP | netnews | |
533 | UDP | netwall, For Emergency Broadcasts | |
540 | TCP | UUCP (Unix-to-Unix Copy Protocol) | |
542 | TCP, UDP | commerce (Commerce Applications) | |
543 | TCP | klogin, Kerberos login | |
544 | TCP | kshell, Kerberos Remote Shell | |
546 | TCP, UDP | DHCPv6 client | |
547 | TCP, UDP | DHCPv6 server | |
548 | TCP | AFP (Apple Filing Protocol) | |
550 | UDP | new-rwho, new-who | |
554 | TCP, UDP | RTSP (Real Time Streaming Protocol) | Offical |
556 | TCP | Remotefs, rfs, rfs_server | |
560 | UDP | rmonitor, Remote Monitor | |
561 | UDP | monitor | |
561 | TCP, UDP | chcmd | |
563 | TCP, UDP | NNTP protocol over TLS/SSL (NNTPS) | Offical |
587 | TCP | Email message submission (SMTP) (RFC 2476) | Offical |
591 | TCP | FileMaker 6.0 Web Sharing (HTTP Alternate, see port 80) | Offical |
593 | TCP, UDP | HTTP RPC Ep Map/Microsoft DCOM | Offical |
604 | TCP | TUNNEL | |
631 | TCP, UDP | IPP, Internet Printing Protocol | |
636 | TCP, UDP | LDAP over SSL (encrypted transmission) | Offical |
639 | TCP, UDP | MSDP, Multicast Source Discovery Protocol | |
646 | TCP | LDP, Label Distribution Protocol | |
647 | TCP | DHCP Failover Protocol | |
648 | TCP | RRP, Registry Registrar Protocol | |
652 | TCP | DTCP, Dynamic Tunnel Configuration Protocol | |
654 | TCP | AODV, Ad hoc On-Demand Distance Vector | |
665 | TCP | sun-dr, Remote Dynamic Reconfiguration | Unoffical |
666 | UDP | Doom, First online FPS | |
674 | TCP | ACAP, Application Configuration Access Protocol | |
691 | TCP | Microsoft Exchange Routing | Offical |
692 | TCP | Hyperwave-ISP | |
695 | TCP | IEEE-MMS-SSL | |
698 | TCP | OLSR, Optimized Link State Routing | |
699 | TCP | Access Network | |
700 | TCP | EPP, Extensible Provisioning Protocol | |
701 | TCP | LMP, Link Management Protocol. | |
702 | TCP | IRIS over BEEP | |
706 | TCP | SILC, Secure Internet Live Conferencing | |
711 | TCP | TDP, Tag Distribution Protocol | |
712 | TCP | TBRPF, Topology Broadcast based on Reverse-Path Forwarding | |
720 | TCP | SMQP, Simple Message Queue Protocol | |
749 | TCP, UDP | kerberos-adm, Kerberos administration | |
750 | UDP | Kerberos version IV | |
782 | TCP | Conserver serial-console management server | |
829 | TCP | CMP (Certificate Management Protocol) | |
860 | TCP | iSCSI | |
873 | TCP | rsync - File synchronisation protocol Offical | |
901 | TCP | Samba Web Administration Tool (SWAT) Unoffical | |
902 | TCP, UDP | VMware Server Unoffical | |
911 | TCP | Network Console on Acid (NCA) - local tty redirection over OpenSSH | |
981 | TCP | SofaWare Technologies Remote HTTPS management for firewall devices running embedded Checkpoint Firewall-1 software | Unoffical |
989 | TCP, UDP | FTP Protocol (data) over TLS/SSL | Offical |
990 | TCP, UDP | FTP Protocol (control) over TLS/SSL | Offical |
991 | TCP, UDP | NAS (Netnews Admin System) | |
992 | TCP, UDP | Telnet protocol over TLS/SSL | Offical |
993 | TCP | IMAP4 over SSL (encrypted transmission) | Offical |
995 | TCP | POP3 over SSL (encrypted transmission) | Offical |
6. systemd ile Sistem Servisi Oluşturalım
Bu servisi yerel VM üzerinde veya sunucu uygulamayı barındıran makine üzerinde oluşturup çalıştıracağız.
- man systemd.unit veya html formda, systemd.unit
Sistem yöneticisi arkadaşlar hali hazırda unit file oluşturmayı genellikle biliyor veya öğrenmesi zor olmayacaktır. Burada oluşturmak istediğim servis tek config dosyasıyla birçok işi yapabilmeli…
Unit file içerisinde Specifiers ismi verilen bir yapı var, hani systemctl restart servis-ismi@ @ işareti çıkıyor ya, tam olarak o @ simgesinden bahsedeceğiz. service dosyaları argüman alabiliyor ve bunu belirli standartlarda yapıyorlar. Specifiers, tümüne girmeyeceğim bize sadece %i lazım.
İhtiyacımız olan temel service dosyası;
/etc/systemd/system/ssh-tunnel@.service
[Unit] Description=Start ssh-tunnel %i After=network.target [Service] ExecStart=/usr/bin/ssh -F /etc/default/ssh-tunnel.config -NT %i RestartSec=5 Restart=always [Install] WantedBy=multi-user.target
4. başlıkta ssh config dosyasından bahsetmiştim, /etc/default/ssh-tunnel.config dosyamız tam olarak sistem servisimizin kullanacağı yapılandırmalara, parametrelere sahip olacak detay için man ssh.
Host * ServerAliveInterval 60 ServerAliveCountMax 3 Host ysnapp_ssh HostName vcs.ysn.app User root Port 2222 IdentityFile /home/yasin/.ssh/parolasiz_yeni GatewayPorts yes RemoteForward 0.0.0.0:22 0.0.0.0:22 ExitOnForwardFailure yes
Yukarıda sadece ssh servisini yerel tcp 22 portunu uzak tcp 22 portuna bağladı, vcs.ysn.app alanı port 22 üzerine yapılan talebin tümü yerel bilgisayarıma gelecektir.
Servisi aktive etmeden önce test edelim,
/usr/bin/ssh -F /etc/default/ssh-tunnel.config -NT ysnapp_ssh
ssh key fingerprint soracaktır, ekleyelim. Komut root yetkileriyle çalıştırılıyor, systemd –user ile kullanıcı için de yapılandırma yapılabilir ancak bir kullanıcının port 1000 ve üzerine redirect işlemi yapabildiği unutulmamalı.
# root olarak; systemctl enable ssh-tunnel@ysnapp_ssh.service Created symlink /etc/systemd/system/multi-user.target.wants/ssh-tunnel@ysnapp_ssh.service → /etc/systemd/system/ssh-tunnel@.service. systemctl start ssh-tunnel@ysnapp_ssh.service systemctl status ssh-tunnel@ysnapp_ssh.service ● ssh-tunnel@ysnapp_ssh.service - Start ssh-tunnel ysnapp_ssh Loaded: loaded (/etc/systemd/system/ssh-tunnel@.service; enabled; vendor preset: enabled) Active: active (running) since Fri 2022-04-08 18:19:30 +03; 2s ago Main PID: 183786 (ssh) Tasks: 1 (limit: 19005) Memory: 896.0K CPU: 19ms CGroup: /system.slice/system-ssh\x2dtunnel.slice/ssh-tunnel@ysnapp_ssh.service └─183786 /usr/bin/ssh -F /etc/default/ssh-tunnel.config -NT ysnapp_ssh Nis 08 18:19:30 uxn-workstation systemd[1]: Started Start ssh-tunnel ysnapp_ssh.
Cloud VM tarafında

Sistemimizin açılışında ssh redirect işlemi otomatik olarak gerçekleşecektir. HTTP için de config dosyamıza ilave yapıp servisi aktive edelim, birkaç tane de kendim ilave ettim bu şekilde yukarıdaki paylaştığım tablodan dilediğiniz uygulama için port redirect yapabilirsiniz.
Host * ServerAliveInterval 60 ServerAliveCountMax 3 Host ysnapp_ssh HostName vcs.ysn.app User root Port 2222 IdentityFile /home/yasin/.ssh/parolasiz_yeni GatewayPorts yes RemoteForward 0.0.0.0:22 0.0.0.0:22 ExitOnForwardFailure yes Host ysnapp_http HostName vcs.ysn.app User root Port 2222 IdentityFile /home/yasin/.ssh/parolasiz_yeni RemoteForward 0.0.0.0:80 0.0.0.0:80 ExitOnForwardFailure yes Host ysnapp_https HostName vcs.ysn.app User root Port 2222 IdentityFile /home/yasin/.ssh/parolasiz_yeni RemoteForward 0.0.0.0:443 0.0.0.0:443 ExitOnForwardFailure yes Host ysnapp_ftp HostName vcs.ysn.app User root Port 2222 IdentityFile /home/yasin/.ssh/parolasiz_yeni RemoteForward 0.0.0.0:21 0.0.0.0:21 ExitOnForwardFailure yes Host ysnapp_mysql HostName vcs.ysn.app User root Port 2222 IdentityFile /home/yasin/.ssh/parolasiz_yeni RemoteForward 0.0.0.0:3306 0.0.0.0:3306 ExitOnForwardFailure yes Host ysnapp_pgsql HostName vcs.ysn.app User root Port 2222 IdentityFile /home/yasin/.ssh/parolasiz_yeni RemoteForward 0.0.0.0:5432 0.0.0.0:5432 ExitOnForwardFailure yes
systemctl enable ssh-tunnel@ysnapp_http systemctl enable ssh-tunnel@ysnapp_mysql systemctl enable ssh-tunnel@ysnapp_pgsql systemctl start ssh-tunnel@ysnapp_http.service systemctl start ssh-tunnel@ysnapp_mysql.service systemctl start ssh-tunnel@ysnapp_pgsql.service


Sistem servisi olarak ssh bağlantısı işlemini görmüş olduk. Kolay gelsin.
Allah’a emanet olun.
Yorumlar kapatıldı.