LINUX.ORG.RU

Подключится по SSH к веб-интерфейсу Syncthing удаленной машины

 , ,


1

1

Привет. Нужно подключится к веб-интерфейсу Syncthing удаленной машины, так, чтобы в его настройках не открывать доступ в локальную сеть. В одной старой теме, мне посоветовали что-то типо этого:

через ssh можно пробрасывать порты. если веб интерфейс висит на сервере на http://localhost:8384/ то ты можешь сделать ssh -L 9999:localhost:8384 server и заходить в веб интерфейс с локального компа через http://localhost:9999/ а трафик будет гоняться до сервера по ssh

Но короче я до конца не понял. Может кто-то мне разъяснить на пальцах как это всё сделать? Сейчас я подключаюсь по SSH по ключу вот такой командой:

sudo ssh -p 54789 -i /media/lpuser/4546-8225/key cluser@192.168.0.100

На пальцах, если у тебя есть постоянный хост с недефолтными опциями, то добавь его в ~/.ssh/config

Host myserver
HostName 192.168.0.100
Port 54789
User cluser
IdentityFile /media/lpuser/4546-8225/key

Потом подключайся по

ssh myserver -N -L 9090:localhost:8384
Yorween
()
Ответ на: комментарий от TheLinuxUser

На стороне девайса, на котором хочешь управлять настройками syncthing на удаленной машине.

Yorween
()

Может кто-то мне разъяснить на пальцах как это всё сделать?

Нет, не может. Если ты к своей готовой команде не можешь -L 9999:localhost:8384 дописать, то в каких терминах прикажешь дальше разъяснять?

t184256 ★★★★★
()
Ответ на: комментарий от Yorween

Ты его только ещё запутаешь, у него зачем-то sudo в команде.

t184256 ★★★★★
()
Ответ на: комментарий от Yorween
ssh host -N -L 9090:localhost:8384

firefox localhost:9090

Подключился по команде, и не сработало, не подключается в браузере. Просто прошла авторизация в консоле.

sudo ssh -i /media/pltuser/4EE6-5712/cluserkey cluser@192.168.0.100 -L 9090:127.0.0.1:8384
TheLinuxUser ★★
() автор топика
Ответ на: комментарий от TheLinuxUser

Добавь к ssh -vvv, не забудь показать, что пишут и ssh и firefox при попытке подключения и будет о чем поговорить.

t184256 ★★★★★
()
Ответ на: комментарий от t184256
OpenSSH_7.9p1 Debian-10+deb10u2, OpenSSL 1.1.1d
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: resolve_canonicalize: hostname 192.168.0.100 is address
debug2: ssh_connect_direct
debug1: Connecting to 192.168.0.100 [192.168.0.100] port 22.
debug1: Connection established.
debug1: identity file /media/cloud/4EE6-5511/keycl type -1
debug1: identity file /media/cloud/4EE6-5511/keycl-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.9p1 Debian-10+deb10u2
debug1: Remote protocol version 2.0, remote software version OpenSSH_8.2p1 Ubuntu-4ubuntu0.1
debug1: match: OpenSSH_8.2p1 Ubuntu-4ubuntu0.1 pat OpenSSH* compat 0x04000000
debug2: fd 3 setting O_NONBLOCK
debug1: Authenticating to 192.168.0.100:22 as 'cloud'
debug3: put_host_port: [192.168.0.100]:22
debug3: hostkeys_foreach: reading file "/root/.ssh/known_hosts"
debug3: record_hostkey: found key type ECDSA in file /root/.ssh/known_hosts:1
debug3: load_hostkeys: loaded 1 keys from [192.168.0.100]:22
debug3: order_hostkeyalgs: prefer hostkeyalgs: ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521
debug3: send packet: type 20
debug1: SSH2_MSG_KEXINIT sent
debug3: receive packet: type 20
debug1: SSH2_MSG_KEXINIT received
debug2: local client KEXINIT proposal
debug2: KEX algorithms: curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256,diffie-hellman-group14-sha1,ext-info-c
debug2: host key algorithms: ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-ed25519-cert-v01@openssh.com,rsa-sha2-512-cert-v01@openssh.com,rsa-sha2-256-cert-v01@openssh.com,ssh-rsa-cert-v01@openssh.com,ssh-ed25519,rsa-sha2-512,rsa-sha2-256,ssh-rsa
debug2: ciphers ctos: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com
debug2: ciphers stoc: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com
debug2: MACs ctos: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: MACs stoc: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: compression ctos: none,zlib@openssh.com,zlib
debug2: compression stoc: none,zlib@openssh.com,zlib
debug2: languages ctos: 
debug2: languages stoc: 
debug2: first_kex_follows 0 
debug2: reserved 0 
debug2: peer server KEXINIT proposal
debug2: KEX algorithms: curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256
debug2: host key algorithms: rsa-sha2-512,rsa-sha2-256,ssh-rsa,ecdsa-sha2-nistp256,ssh-ed25519
debug2: ciphers ctos: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com
debug2: ciphers stoc: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com
debug2: MACs ctos: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: MACs stoc: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: compression ctos: none,zlib@openssh.com
debug2: compression stoc: none,zlib@openssh.com
debug2: languages ctos: 
debug2: languages stoc: 
debug2: first_kex_follows 0 
debug2: reserved 0 
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug3: send packet: type 30
debug1: expecting SSH2_MSG_KEX_ECDH_REPL
debug3: receive packet: type 31
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:uDavcs22mebmfQnmQIXC9fpFDN8
debug3: put_host_port: [192.168.0.100]:22
debug3: put_host_port: [192.168.0.100]:22
debug3: hostkeys_foreach: reading file "/root/.ssh/known_hosts"
debug3: record_hostkey: found key type ECDSA in file /root/.ssh/known_hosts:1
debug3: load_hostkeys: loaded 1 keys from [192.168.0.100]:22
debug3: hostkeys_foreach: reading file "/root/.ssh/known_hosts"
debug3: record_hostkey: found key type ECDSA in file /root/.ssh/known_hosts:1
debug3: load_hostkeys: loaded 1 keys from [192.168.0.100]:22
debug1: Host '[192.168.0.100]:22' is known and matches the ECDSA host key.
debug1: Found key in /root/.ssh/known_hosts:1
debug3: send packet: type 21
debug2: set_newkeys: mode 1
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug3: receive packet: type 21
debug1: SSH2_MSG_NEWKEYS received
debug2: set_newkeys: mode 0
debug1: rekey after 134217728 blocks
debug1: Will attempt key: /media/cloud/4EE6-5511/keycl  explicit
debug2: pubkey_prepare: done
debug3: send packet: type 5
debug3: receive packet: type 7
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,sk-ssh-ed25519@openssh.com,ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,sk-ecdsa-sha2-nistp256@openssh.com>
debug3: receive packet: type 6
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug3: send packet: type 50
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey
debug3: start over, passed a different list publickey
debug3: preferred gssapi-keyex,gssapi-with-mic,publickey,keyboard-interactive,password
debug3: authmethod_lookup publickey

Браузер тот раз писал что нет такой страницы или что-то в этом духе. Сейчас просто висит в постоянной загрузке.

TheLinuxUser ★★
() автор топика
Ответ на: комментарий от t184256

Часть 2

debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /media/cloud/4EE6-5511/keycl
Enter passphrase for key '/media/cloud/4EE6-5511/keycl': 
debug3: sign_and_send_pubkey: RSA SHA256:3DxvmPcQnfamEJgRde7aHVo
debug3: sign_and_send_pubkey: signing using rsa-sha2-512
debug3: send packet: type 50
debug2: we sent a publickey packet, wait for reply
debug3: receive packet: type 52
debug1: Authentication succeeded (publickey).
Authenticated to 192.168.0.100 ([192.168.0.100]:22).
debug1: Local connections to LOCALHOST:9090 forwarded to remote address 127.0.0.1:8384
debug3: channel_setup_fwd_listener_tcpip: type 2 wildcard 0 addr NULL
debug3: sock_set_v6only: set socket 4 IPV6_V6ONLY
debug1: Local forwarding listening on ::1 port 9090.
debug2: fd 4 setting O_NONBLOCK
debug3: fd 4 is O_NONBLOCK
debug1: channel 0: new [port listener]
debug1: Local forwarding listening on 127.0.0.1 port 9090.
debug2: fd 5 setting O_NONBLOCK
debug3: fd 5 is O_NONBLOCK
debug1: channel 1: new [port listener]
debug1: channel 2: new [client-session]
debug3: ssh_session2_open: channel_new: 2
debug2: channel 2: send open
debug3: send packet: type 90
debug1: Requesting no-more-sessions@openssh.com
debug3: send packet: type 80
debug1: Entering interactive session.
debug1: pledge: network
debug3: receive packet: type 80
debug1: client_input_global_request: rtype hostkeys-00@openssh.com want_reply 0
debug3: receive packet: type 4
debug1: Remote: /home/cloud/.ssh/authorized_keys:1: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding
debug3: receive packet: type 91
debug2: channel_input_open_confirmation: channel 2: callback start
debug2: fd 3 setting TCP_NODELAY
debug3: ssh_packet_set_tos: set IP_TOS 0x10
debug2: client_session2_setup: id 2
debug2: channel 2: request pty-req confirm 1
debug3: send packet: type 98
debug1: Sending environment.
debug3: Ignored env COLORTERM
debug1: Sending env LANG = uk_UA.UTF-8
debug2: channel 2: request env confirm 0
debug3: send packet: type 98
debug3: Ignored env TERM
debug3: Ignored env DISPLAY
debug3: Ignored env PATH
debug3: Ignored env MAIL
debug3: Ignored env LOGNAME
debug3: Ignored env USER
debug3: Ignored env HOME
debug3: Ignored env SHELL
debug3: Ignored env SUDO_COMMAND
debug3: Ignored env SUDO_USER
debug3: Ignored env SUDO_UID
debug3: Ignored env SUDO_GID
debug2: channel 2: request shell confirm 1
debug3: send packet: type 98
debug2: channel_input_open_confirmation: channel 2: callback done
debug2: channel 2: open confirm rwindow 0 rmax 32768
debug3: receive packet: type 99
debug2: channel_input_status_confirm: type 99 id 2
debug2: PTY allocation request accepted on channel 2
debug2: channel 2: rcvd adjust 2097152
debug3: receive packet: type 99
debug2: channel_input_status_confirm: type 99 id 2
debug2: shell request accepted on channel 2
Welcome to Ubuntu 20.04.1 LTS (GNU/Linux 5.4.0-1025-raspi aarch64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

 System information disabled due to load higher than 4.0

cloud@cloud:~$ debug1: Connection to port 9090 forwarding to 127.0.0.1 port 8384 requested.
debug2: fd 9 setting TCP_NODELAY
debug2: fd 9 setting O_NONBLOCK
debug3: fd 9 is O_NONBLOCK
debug1: channel 3: new [direct-tcpip]
debug3: send packet: type 90
debug3: receive packet: type 92
channel 3: open failed: connect failed: Connection timed out
debug2: channel 3: zombie
debug2: channel 3: garbage collecting
debug1: channel 3: free: direct-tcpip: listening port 9090 for 127.0.0.1 port 8384, connect from 127.0.0.1 port 35460 to 127.0.0.1 port 9090, nchannels 4
debug3: channel 3: status: The following connections are open:
  #2 client-session (t4 r0 i0/0 o0/0 e[write]/0 fd 6/7/8 sock -1 cc -1)

debug1: Connection to port 9090 forwarding to 127.0.0.1 port 8384 requested.
debug2: fd 9 setting TCP_NODELAY
debug2: fd 9 setting O_NONBLOCK
debug3: fd 9 is O_NONBLOCK
debug1: channel 3: new [direct-tcpip]
debug3: send packet: type 90
debug3: receive packet: type 92
channel 3: open failed: connect failed: Connection timed out
debug2: channel 3: zombie
debug2: channel 3: garbage collecting
debug1: channel 3: free: direct-tcpip: listening port 9090 for 127.0.0.1 port 8384, connect from 127.0.0.1 port 35556 to 127.0.0.1 port 9090, nchannels 4
debug3: channel 3: status: The following connections are open:
  #2 client-session (t4 r0 i0/0 o0/0 e[write]/0 fd 6/7/8 sock -1 cc -1)

debug1: Connection to port 9090 forwarding to 127.0.0.1 port 8384 requested.
debug2: fd 9 setting TCP_NODELAY
debug2: fd 9 setting O_NONBLOCK
debug3: fd 9 is O_NONBLOCK
debug1: channel 3: new [direct-tcpip]
debug3: send packet: type 90

TheLinuxUser ★★
() автор топика
Ответ на: комментарий от TheLinuxUser
debug1: Connection to port 9090 forwarding to 127.0.0.1 port 8384 requested.
...
channel 3: open failed: connect failed: Connection timed out

Значит даже на удаленном компе нельзя подключиться к 127.0.0.1 port 8384. Про форвардинг можно временно забыть, все дальнейшие разборки ограничить удаленным хостом.

Что скажет nmap localhost -p 22,8384,8888,54321, открыт ли порт? Почему ты решил, что syncthing слушает на 127.0.0.1 8384?

t184256 ★★★★★
()
Ответ на: комментарий от t184256

Что скажет nmap localhost -p 22,8384,8888,54321

Starting Nmap 7.80 ( https://nmap.org ) at 2021-11-10 15:14 UTC Failed to resolve «localhost». WARNING: No targets were specified, so 0 hosts scanned. Nmap done: 0 IP addresses (0 hosts up) scanned in 0.09 seconds

открыт ли порт?

Порты у меня закрыты все кроме ssh (измененного) и открыты 8384 для локальных устройств (с которого и пытался подключится). Всё отрабатывает кроме вот такого подключения.

iptables -A INPUT -i eth0 -p tcp --dport 8384 -m iprange --src-range 192.168.0.102-192.168.0.103 -m comment --comment "ALLOW Syncthing Notebook" -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp --sport 8384 -m iprange --dst-range 192.168.0.102-192.168.0.103 -m comment --comment "ALLOW Syncthing Notebook" -j ACCEPT

Почему ты решил, что syncthing слушает на 127.0.0.1 8384?

Потому что я на ноуте захожу в веб интерфейс через 127.0.0.1:8384, на сервере в конфиге такой же указан.

TheLinuxUser ★★
() автор топика
Последнее исправление: TheLinuxUser (всего исправлений: 1)
Ответ на: комментарий от TheLinuxUser

Забудь пока про ноут, нет никакого ноута.

Failed to resolve «localhost»

Facepalm. nmap 127.0.0.1 -p 22,8384,8888,54321? nc -vvv 127.0.0.1 8384? Любой другой существенный пруф, что он слушает 8384 и даёт самому себе к 8384 подключаться?

t184256 ★★★★★
()
Ответ на: комментарий от t184256

nmap 127.0.0.1 -p 22,8384,8888,54321

Starting Nmap 7.80 ( https://nmap.org ) at 2021-11-18 14:06 UTC
Note: Host seems down. If it is really up, but blocking our ping probes, try -Pn
Nmap done: 1 IP address (0 hosts up) scanned in 3.10 seconds

nc -vvv 127.0.0.1 8384

nc: connect to 127.0.0.1 port 8384 (tcp) failed: Connection timed out
TheLinuxUser ★★
() автор топика
Ответ на: комментарий от TheLinuxUser

а точно синхфинг работает на удаленной машине ??
что показывает htop к примеру ??
что пишет синхфинг в логи ??

pfg ★★★★★
()
Ответ на: комментарий от pfg

а точно синхфинг работает на удаленной машине ??

Точно, я на ней работаю каждый день (NAS), прихожу домой, и на домашнем ПК уже все файлы актуальны. Это прям 100%.

TheLinuxUser ★★
() автор топика
Последнее исправление: TheLinuxUser (всего исправлений: 1)
Ответ на: комментарий от TheLinuxUser

try -Pn

try -Pn

nc: connect to 127.0.0.1 port 8384 (tcp) failed: Connection timed out

Не слушает syncthing адрес 127.0.0.1 порт 8384 на этой машине => тема не про SSH и проброс, а про твои ложные предположения. 8888 пробовал?

t184256 ★★★★★
()
Ответ на: комментарий от TheLinuxUser

ага, логи он шлет на stdout. так что смотри что он выдает через journalctl или что у тебя
https://docs.syncthing.net/users/autostart.html#linux
я stdout stderr сливал в /var/log а то синх слишком много срал в системный лог

/etc/systemd/system/syncthing@pfg.service.d/override.conf    
[Service]          
Group=%i             
Nice=10            
StandardOutput=file:/var/log/syncthing.out            
StandardError=file:/var/log/syncthing.err

еще глянь какой порт оне слушают для веб-интерфейса
https://docs.syncthing.net/users/config.html#gui-element

pfg ★★★★★
()
Последнее исправление: pfg (всего исправлений: 2)
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.