ubuntu 22.04 로 업그레이드 후에 기존 autossh 로 설정해놓은 터널링이 안된다.
그래서 확인해보니. autossh 가 실패되었다.

더 확인해보니 ssh 로 접속이 안되고, 암호를 물어본다.

ssh -vvv 로 접속해서 메시지를 확인해봤다.

다음과 같은 메시지가 보인다.

ssh send_pubkey_test no mutual signature algorithm
or
sign_and_send_pubkey: no mutual signature supported

검색해 보니, 보안관련 이슈인듯 싶다.

일단 해결방안은 아래 링크로

https://transang.me/ssh-handshake-is-rejected-with-no-mutual-signature-algorithm-error/

https://confluence.atlassian.com/bitbucketserverkb/ssh-rsa-key-rejected-with-message-no-mutual-signature-algorithm-1026057701.html

위 방법중 임시방편? 으로 일단 해결해본다.

.ssh/config 에 접속설정을 추가한다.

Host server-nickname
        hostname servername.com
        User root
        Port 2222
        PubkeyAcceptedKeyTypes +ssh-rsa

추천하는 방법은 보안성에 좋은 key 를 재생성해서 사용하는 것 같다.
추후 시간내서 조치해야 겠다.

 

반응형

WRITTEN BY
1day1
하루하루 즐거운일 하나씩, 행복한일 하나씩 만들어 가요.

,

예전에 우분투에서 autossh 를 설정하는 법을 정리했었다.( blog.1day1.org/615 )

맥미니 도 같이 쓰고 있는데, 맥미니도 설정해보고자 한다.(그동안 딱히 사용할 일은 없었다.)

맥에서는 brew 로 autossh 를 설치한다.

brew install autossh

이제 자동으로 실행되도록 설정한다. 우분투의 systemd 와 비슷한 launchctl 을 사용한다.

다음과 같은 설정.( ooo.plist 파일은 임의로 만들면 된다. )

$ cat Library/LaunchAgents/org.1day1.macmini.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    	<string>1day1 org macmini</string>
    <key>KeepAlive</key>
    	<true/>
    <key>RunAtLoad</key>
    	<true/>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/local/bin/autossh</string>
	<!-- autossh switches -->
        <string>-M</string>
        <string>0</string>
	<!-- ssh switches -->
        <string>-N</string>
        <string>-T</string>
	<string>-o</string>
	        <string>ControlMaster no</string>
	<string>-o</string>
        	<string>ServerAliveInterval 60</string>
	<string>-o</string>
        	<string>ServerAliveCountMax 3</string>
	<string>-p</string>
        	<string>2222</string>
	<string>-l</string>
        	<string>root</string>
	<string>-i</string>
        	<string>/Users/your-mac-user-name/.ssh/id_rsa</string>
	<string>-R</string>
        	<string>9191:127.0.0.1:5900</string>
	<string>-R</string>
        	<string>9122:127.0.0.1:22</string>
	<string>your-externel-server</string>
    </array>
</dict>
</plist>

-p 2222 -l root -i 비밀키 , your-externel-server  => 이 부분들은 본인에 맞게 수정해서 사용한다.

다음처럼 실행.

launchctl load -S Aqua Library/LaunchAgents/org.1day1.macmini.plist 

실행되어 있는지 확인.

$ launchctl list |grep 1day1
23391	0	1day1 org macmini

터널링 서버에 접속이 되어 있는지 확인한다.

이제 임의의 곳에서 맥미니에 접속할 수 있게 된다.

 

반응형

WRITTEN BY
1day1
하루하루 즐거운일 하나씩, 행복한일 하나씩 만들어 가요.

,

공유기 등 내부망에 있어서 외부 접속이 어려운 환경에서 접속할 수 있게 할 수 있다.

터널링을 통해 가능하다. ssh 로 접속해 있을 수 있는 호스팅 환경이 있으면 된다.

apt install autossh

설치는 쉽다.

systemd / upstart 방식에 따라 자동 실행 설정이 조금 다르다.

# systemd 방식 (최근 배포판)

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

[Service]
ExecStart=/usr/bin/autossh -M 0 -q -N \
-i /root/.ssh/id_rsa \
-o "ServerAliveInterval 60" -o "ServerAliveCountMax 3" your-externel-server \
-R 5991:127.0.0.1:5901 \
-R 5922:127.0.0.1:22 \
-R 5989:192.168.11.19:5900

[Install]
WantedBy=multi-user.target

위 설정처럼 하면 된다. 자신의 맞는 환경에 따라 수정해서 사용하면 된다.
내부 서비스(5901 , 22) 로 접속가능하고, 또는 동일네트워크 다른 서버로도 접속가능하다.

위 파일 생성 후 다음 명령으로 실행해준다.

systemctl enable autossh
systemctl start autossh

 

# upstart 방식 (예전 방식)

# vi /etc/init/autossh.conf 
description "autossh daemon for ssh tunnel"

start on net-device-up IFACE=eth0
stop on runlevel [01S6]

#setuid autossh

respawn
respawn limit 5 60

script
export AUTOSSH_FIRST_POLL=30
export AUTOSSH_GATETIME=0
export AUTOSSH_POLL=60
/usr/bin/autossh -M 0 -q -N \
-i /root/.ssh/id_rsa \
-o "ServerAliveInterval 60" -o "ServerAliveCountMax 3" your-externel-server \
-R 5991:127.0.0.1:5901 \
-R 5922:127.0.0.1:22 \
-R 5989:192.168.11.19:5900
end script

설정 방식만 조금 다를 뿐 사용법은 동일하다.

 

그럼, 제 3의 위치에서 터널링으로 뚫어 놓은 내부서버에 접속해본다.
당연히 바로 접속 할 수는 없다.

다음의 ssh 명령으로  {로컬PC} => 외부 서버 => 내부망(터널링)  으로 접속한다.

ssh your-externel-server -L 5991:127.0.0.1:5991 -L 5922:127.0.0.1:5922 

위 설정은 로컬PC 의 포트로 터널링한 내부망의 서비스 포트와 연결하는 것이다.

ssh root@localhost -p 5922

내부에서 다음 처럼 접속하면 된다. (위 예시는 내부망의 22번 ssh 포트로 접속하는 명령)

조금 복잡해 보일 수 있지만, 흐름을 이해하면 크게 어렵지는 않다.

내부망에 포트포워딩으로 접근할 수 없는 경우, 보안접속이 필요한 서비스 등에 사용할 수 있다.
기본적으로 ssh 를 이용한 것이라 vpn 처럼 보안접속이 필요한 경우등에 유용할 듯 싶다.

 

[추가]

systemd 방식 설정 후 재부팅했는데, autossh 가 실행이 안되는 경우

다음과 같은 에러가 날때 (systemctl status autossh 로 확인)

ssh exited prematurely with status 255; autossh exiting

구글링 해보니, After=network-online.target 대신에

After=network.target
After=NetworkManager-wait-online.service

등등 여러개로 바꿔가며 해봐도 안된다. 네트워크가 정상 접속되는 시점이 차이가 있는 듯 하다.

 

# vi /etc/systemd/system/autossh.service 에 다음 항목을 추가해준다.

[Service]
ExecStartPre=/bin/sh -c 'until ping -c1 google.com; do sleep 1; done;'

 

위 처럼 네트워크가 동작하는지 체크 후에 실행하도록 한다. ( 완료 후 systemctl daemon-reload 로 설정을 재로딩 해준다)

반응형

WRITTEN BY
1day1
하루하루 즐거운일 하나씩, 행복한일 하나씩 만들어 가요.

,