카테고리 없음

SSH Tunnel 설정

Lawmin 2022. 6. 22. 11:21
# wget https://www.harding.motd.ca/autossh/autossh-1.4g.tgz
# gunzip -c autossh-1.4g.tgz | tar xvf -
cd autossh-1.4g
./configure
make
make install

# vi /etc/systemd/system/autossh.service
[Unit]
Description=Keep reverse ssh tunnel
After=network-online.target ssh.service

[Service]
Type=forking
User=lawmin
Environment="AUTOSSH_GATETIME=0"
ExecStart=/usr/local/bin/autossh -M 0 -o ExitOnForwardFailure=yes -f -N -R SSH서버쪽의포트1:localhost:클라이언트쪽의포트1 -R SSH서버쪽의포트2:localhost:클라이언트쪽의포트2 SSH서버계정@SSH서버주소 -p SSH서버포트
ExecStop=/bin/kill -HUP $MAINPID
Restart=always
RestartSec=5

[Install]
WantedBy=multi-user.target
(:wq 저장)

# systemctl enable autossh
# systemctl start autossh

중계서버를 두고 S2C(Server To Client) 방식으로 설정해두면, (필요 시 여러 서버도 연결 가능)

클라이언트에서 C2S(Client To Server)로 접속 가능하다.