User Tools

Site Tools


сервис_ssh

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
сервис_ssh [2022/10/26 13:31]
val [Windows]
сервис_ssh [2026/09/17 14:53] (current)
val [Настройка ssh сервера]
Line 2: Line 2:
  
   * [[http://​ru.wikipedia.org/​wiki/​SSH|SSH (wikipedia)]]   * [[http://​ru.wikipedia.org/​wiki/​SSH|SSH (wikipedia)]]
 +  * [[https://​habr.com/​ru/​articles/​747080/​|SSH с высоты птичьего полёта,​ или разгребаем кучи ключей]]
   * [[https://​www.serfish.com/​console/​|Web-based access to any SSH server]]   * [[https://​www.serfish.com/​console/​|Web-based access to any SSH server]]
   * [[http://​linux.bolden.ru/​ssh-tunnels/​|Подробный анализ теории и практики использования SSH-туннелей]]   * [[http://​linux.bolden.ru/​ssh-tunnels/​|Подробный анализ теории и практики использования SSH-туннелей]]
   * [[https://​m.habr.com/​post/​435546/​|Практические советы,​ примеры и туннели SSH]]   * [[https://​m.habr.com/​post/​435546/​|Практические советы,​ примеры и туннели SSH]]
 +  * [[https://​habr.com/​ru/​articles/​122445/​|Памятка пользователям ssh]]
  
 ===== Установка ===== ===== Установка =====
Line 10: Line 12:
 ==== Windows ==== ==== Windows ====
  
 +=== Windows Power Shell ===
 +<​code>​
 +$ export NO_COLOR=1
 +</​code>​
 === PuTTY === === PuTTY ===
   * [[http://​www.putty.org/​|PuTTY]]   * [[http://​www.putty.org/​|PuTTY]]
Line 19: Line 25:
  
 HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\SshHostKeys HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\SshHostKeys
 +</​code>​
 +
 +=== MobaXterm ===
 +
 +  * [[https://​mobaxterm.mobatek.net/​|MobaXterm]]
 +  * [[https://​bbs.archlinux.org/​viewtopic.php?​id=174595|Weird characters while pasting in terminal]]
 +<​code>​
 +printf "​\e[?​2004l"​
 </​code>​ </​code>​
  
Line 25: Line 39:
   * [[https://​winscp.net/​eng/​docs/​lang:​ru|WinSCP]]   * [[https://​winscp.net/​eng/​docs/​lang:​ru|WinSCP]]
   * [[http://​val.bmstu.ru/​unix/​SSH/​WinSCP-5.19.2-Setup.exe]]   * [[http://​val.bmstu.ru/​unix/​SSH/​WinSCP-5.19.2-Setup.exe]]
 +
 +=== Tabby ===
 +
 +  * [[https://​tabby.sh/​|A terminal for the modern age]]
 ==== Ubuntu/​Debian ==== ==== Ubuntu/​Debian ====
 <​code>​ <​code>​
Line 32: Line 50:
 ===== Настройка ssh сервера ===== ===== Настройка ssh сервера =====
 <​code>​ <​code>​
-gate# cat /​etc/​ssh/​sshd_config+gate# less /​etc/​ssh/​sshd_config
 </​code><​code>​ </​code><​code>​
 ... ...
-Port 2222+#​PermitRootLogin prohibit-password
 ... ...
-DenyUsers "user*"+Include /​etc/​ssh/​sshd_config.d/​*.conf
 ... ...
 +</​code><​code>​
 +gate# cat /​etc/​ssh/​sshd_config.d/​my.conf
 +</​code><​code>​
 +Port 2222
 +
 +DenyUsers "​user*"​
 +
 PermitRootLogin yes PermitRootLogin yes
-...+ 
 +#​KexAlgorithms +diffie-hellman-group1-sha1,​diffie-hellman-group-exchange-sha1 
 +#​HostkeyAlgorithms +ssh-dss,​ssh-rsa 
 +#​PubkeyAcceptedKeyTypes +ssh-dss,​ssh-rsa
 </​code>​ </​code>​
  
Line 51: Line 79:
 <​code>​ <​code>​
 gate# ssh-keygen -l -f /​etc/​ssh/​ssh_host_dsa_key.pub gate# ssh-keygen -l -f /​etc/​ssh/​ssh_host_dsa_key.pub
 +</​code>​
 +<​code>​
 +ubuntu24# systemctl edit ssh.socket
 +...
 +[Socket]
 +ListenStream=
 +ListenStream=0.0.0.0:​2222
 +...
 +ubuntu24# systemctl restart ssh.socket
 </​code>​ </​code>​
  
Line 62: Line 99:
 $ mkdir .ssh/ $ mkdir .ssh/
  
-$ cat .ssh/config+$ cat ~/.ssh/config
 </​code><​code>​ </​code><​code>​
 Host * Host *
   ServerAliveInterval 10   ServerAliveInterval 10
  
-#Host server2+#Host gitlab
 #        Port 2222 #        Port 2222
-#        User backup+##        User root 
 + 
 +#Host gate 
 +#    HostName 192.168.X.1 
 +#    User root 
 +#    IdentityFile ~/​.ssh/​id_rsa
  
-#Host switch* ​192.168.X.3 192.168.X.4 ​192.168.X.5*+#Host switch* 192.168.X.5*
 #        KexAlgorithms +diffie-hellman-group1-sha1 #        KexAlgorithms +diffie-hellman-group1-sha1
 #        Ciphers +aes128-cbc #        Ciphers +aes128-cbc
Line 77: Line 119:
 #        StrictHostKeyChecking=no #        StrictHostKeyChecking=no
 #        LogLevel ERROR #        LogLevel ERROR
 +#        HostKeyAlgorithms +ssh-rsa
 +#        PubkeyAcceptedKeyTypes +ssh-rsa
 </​code>​ </​code>​
  
Line 96: Line 140:
 student@hostX$ cd /; sudo tar -cf - etc/ | ssh -l user1 gate "cat > etc.tar"​ student@hostX$ cd /; sudo tar -cf - etc/ | ssh -l user1 gate "cat > etc.tar"​
  
-server# ssh switch ​"show cdp neighbors"​+server# ssh switch1 ​"show cdp neighbors"​
 </​code>​ </​code>​
  
 ==== SSH вместо RCP (SCP) ==== ==== SSH вместо RCP (SCP) ====
 +==== SCP ====
 <​code>​ <​code>​
 $ scp -P 2222 val@radio.specialist.ru:/​usr/​local/​www/​apache22/​data/​unix/​virus.zip . $ scp -P 2222 val@radio.specialist.ru:/​usr/​local/​www/​apache22/​data/​unix/​virus.zip .
  
 server# scp switchN:​running-config /​srv/​tftp/​switchN-running-config server# scp switchN:​running-config /​srv/​tftp/​switchN-running-config
 +deb12_ub24# scp -O switchN:​running-config /​srv/​tftp/​switchN-running-config
  
 server# sshpass -p cisco scp switchN:​running-config /​srv/​tftp/​switchN-running-config server# sshpass -p cisco scp switchN:​running-config /​srv/​tftp/​switchN-running-config
 +
 +server# scp -3 192.168.X.101:/​etc/​docker/​daemon.json gate:/​etc/​docker/​daemon.json
 </​code>​ </​code>​
  
Line 113: Line 161:
  
 <​code>​ <​code>​
-www# cat /​etc/​ssh/​sshd_config+# cat /​etc/​ssh/​sshd_config
 </​code><​code>​ </​code><​code>​
 ... ...
Line 120: Line 168:
 ... ...
 Match group user1 Match group user1
 +#Match group group1
        ​ChrootDirectory %h        ​ChrootDirectory %h
        ​ForceCommand internal-sftp        ​ForceCommand internal-sftp
 </​code><​code>​ </​code><​code>​
-www# chown root ~user1/+# chown root:​www-data ​~user1/
  
-wwwmkdir ~user1/public_html+debian13chmod 755 ~user1/
  
-www# chown -R user1:user1 ~user1/​public_html/​+mkdir ~user1/​public_html && ​chown user1:user1 ~user1/​public_html
 + 
 +# mkdir ~user1/mail && chown user1:user1 ~user1/mail/
 </​code>​ </​code>​
  
Line 145: Line 196:
  
 ==== SSH вместо VPN (привязка к порту клиента) ==== ==== SSH вместо VPN (привязка к порту клиента) ====
 +
 +==== Local Port Forwarding Tunnel ====
 +
 <​code>​ <​code>​
 windows desktop windows desktop
Line 160: Line 214:
  
 ==== SSH вместо VPN (привязка к порту сервера) ==== ==== SSH вместо VPN (привязка к порту сервера) ====
 +==== Remote Port Forwarding Tunnel ====
  
   * [[Управление сервисами в Linux]]   * [[Управление сервисами в Linux]]
 +  * [[Управление ядром и модулями в Linux#​Переменные ядра]]
  
 <​code>​ <​code>​
Line 170: Line 226:
 ... ...
 </​code><​code>​ </​code><​code>​
-lan# ssh -N -R 2222:​localhost:​22 ​user1@server.corpX.un+lan# ssh -N -R 61022:​localhost:​22 ​-o ServerAliveInterval=5 -o ServerAliveCountMax=1 -o ExitOnForwardFailure=yes student@server.corpX.un 
 + 
 +lan# ssh -N -R 61389:​192.168.100+X.1NN:​3389 student@server.corpX.un 
 + 
 +mobaxterm>​ ssh -N -R 61389:​localhost:​3389 student@server.corpX.un
  
-lan# ssh -N -R 3101:192.168.100+X.101:3389 user1@server.corpX.un+mobaxterm> ​ssh -N -R 0:localhost:5500 student@server.corpX.un
 </​code>​ </​code>​
  
Line 182: Line 242:
 </​code><​code>​ </​code><​code>​
 ... ...
-Match Address 192.168.X.1+#AllowUsers root user*@10.5.*.* 
 +... 
 +Match Address 192.168.*.*,​172.16.*.*
        ​PermitRootLogin yes        ​PermitRootLogin yes
 </​code>​ </​code>​
Line 212: Line 274:
  
 <​code>​ <​code>​
-node1:~# cat .ssh/config+node1:~# cat ~/.ssh/config
 </​code><​code>​ </​code><​code>​
 Host * Host *
Line 233: Line 295:
 ==== Парольная аутентификация ==== ==== Парольная аутентификация ====
 <​code>​ <​code>​
-# apt install sshpass+server# apt install sshpass
  
-[gate.isp.un:​~] ​# sshpass -p '123' ssh 172.16.1.13+server# sshpass -p 'strongpassword' ssh vagrant@node1
  
 server# sshpass -p cisco ssh switchN server# sshpass -p cisco ssh switchN
Line 246: Line 308:
 === Настройка sshd на использование ключей === === Настройка sshd на использование ключей ===
 <​code>​ <​code>​
-gate# less /​etc/​ssh/​sshd_config+# less /​etc/​ssh/​sshd_config
 </​code><​code>​ </​code><​code>​
 ... ...
Line 256: Line 318:
 === Генерация ключей === === Генерация ключей ===
 <​code>​ <​code>​
-user1@client1:​~$ ​ssh-keygen+ssh-keygen
 </​code><​code>​ </​code><​code>​
 ... ...
-Enter passphrase (empty for no passphrase): ​password1+Enter passphrase (empty for no passphrase): ​ENTER
 ... ...
 </​code><​code>​ </​code><​code>​
-user1@client1:​~$ ​ls .ssh/+ls .ssh/
 </​code>​ </​code>​
  
Line 270: Line 332:
  
 <​code>​ <​code>​
-linux$ ​ssh-copy-id gate +ssh-copy-id ​userX@gate.isp.un
- +
-linux$ ssh-copy-id server +
- +
-freebsd$ ssh-copy-id -i .ssh/id_rsa.pub gate+
 </​code>​ </​code>​
  
сервис_ssh.1666780267.txt.gz · Last modified: 2022/10/26 13:31 by val