Показаны сообщения с ярлыком ssh. Показать все сообщения
Показаны сообщения с ярлыком ssh. Показать все сообщения

пятница, 28 мая 2010 г.

SSH tunnelling

Сначала своими словами. Простой пример. Необходимо зайти на веб сервер по шифрованому соединению... ну или воспользоваться любой другой службой этого сервера секьюрно. Там стоит sshd.



На машине клиенте ssh -L 1234:localhost:80 om@192.168.1.1. Это означает, что с 1234 порта ip адреса 127.0.0.1 пакет будет перенаправлен на адрес 192.168.1.1 порт 80 внутри SSH трубы. Для проверки вбейте в адресной строке браузера http://localhost:1234.

Далее оригинал статьи. http://www.brandonhutchinson.com/ssh_tunnelling.html



ssh tunnelling is an excellent way to tunnel insecure protocols through a secure communication channel. In this example, I'll tunnel POP3 traffic using ssh. Traditional POP3 traffic, including username and password information, travels clear-text across the network.

OpenSSH is used in the following examples.

To tunnel POP3 traffic using ssh:

1. Make sure an ssh client is installed on your machine and an ssh server is installed on the POP3 server.

2. Create a local ssh tunnel on your machine (port 1234 for this example) to the POP3 server's port 110. You will need to be the root user to bind to "privileged" ports (< 1024).
# ssh -f -N -L 1234:localhost:110 user@POP3_server

3. Test the tunnel.
$ telnet localhost 1234
You should see the POP3 server's banner information.

4. Configure your mail client to access your mail via POP3 using mail server localhost and port 1234.

"Reverse" ssh tunnel
It is possible to create a "reverse" ssh tunnel. The reverse tunnel will allow you to create an ssh tunnel from your work computer to your home computer, for example, and then login to your work machine from your home machine even if your work firewall does not permit ssh traffic initiated from your home machine!

For this to work, an ssh server must be installed on your work and home computer, and ssh (TCP port 22) must be allowed outbound from your work computer to your home computer.

$ ssh -R remote_port:localhost:22 your_home_computer

ex. $ ssh -R 2048:localhost:22 home.computer.com

At home, you would then run ssh -p 2048 localhost to log into your work computer via ssh.

четверг, 25 февраля 2010 г.

ssh deny user

Полезная вещь.

Allow only some users to login
Ok, you now have disabled root login, but any user account on your system will be authorized to remote login. This brings a lot of issues, because more users, means more distributed logins, more chances to security issues (imagine one of your users being kidnapped by a alien, you never know). So authorize one user (you), and if needed, other users, but only if needed. I hope you never left sshd_config, because now we have to search for the line “AllowUsers”. If this line doesn’t exist, add it, in the “#Authentication” part of the file, and specify the users you want to allow login. Example: “AllowUsers user1 user2“. Easy right? Let’s continue.

Оригинал: http://blog.dbugs.org/2007/08/29/ssh-security/

пятница, 28 августа 2009 г.

ssh без пароля под linux и windows

Аутентификация по RSA ключам - удобная штука. Рассмотрим 2 варианта. Unix клиент - Unix сервер и Windows клиент - Unix сервер. На сервере должен быть поднят sshd. Файл конфигурации:
/etc/ssh/sshd_config
Protocol 2
Port 22
ListenAddress ::
AllowTcpForwarding no
GatewayPorts no
X11Forwarding yes
X11DisplayOffset 10
X11UseLocalhost yes
PrintMotd no
KeepAlive yes
SyslogFacility auth
LogLevel info
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
ServerKeyBits 768
KeyRegenerationInterval 3600
StrictModes yes
LoginGraceTime 600
MaxAuthTries 6
MaxAuthTriesLog 3
PermitEmptyPasswords no
PasswordAuthentication yes
PAMAuthenticationViaKBDInt yes
PermitRootLogin no
Subsystem sftp /usr/lib/ssh/sftp-server
IgnoreRhosts yes
RhostsAuthentication no
RhostsRSAAuthentication no
RSAAuthentication yes

Для того, чтобы подключиться с одной Unix машины на другую делаем следующее. На клиенте (с которой будем заходить) генерим пару ключей private/public.

om@rnd1 # ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (//.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in //.ssh/id_rsa.
Your public key has been saved in //.ssh/id_rsa.pub.
The key fingerprint is:
14:fb:6d:ed:4b:af:d2:86:d3:e8:e7:50:4e:51:55:1b root@rnd1

Далее заходим на сервер (к которому будем подключаться) под пользователем om (к примеру). Наша цель - получить беспарольную аутентификация для пользователя om. В папке пользователя есть директория .ssh. Cоздаём в ней файл authorized_keys.

bash-2.05$ pwd
/export/home/om
bash-2.05$ cd .ssh/
bash-2.05$ touch authorized_keys

Вставляем в него public ключ. В результате получаем файл:
bash-2.05$ cat authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEAnsRA4X58e33MBxU3iSiVjjB91x4tLyTlbr90Qk5RoZMnaejnEjKfxaCzKLhBR6MOViugjJe6sXhpuCOeBu1LYL2IyIkSrm+Q/NfDgNWnXkHZWLx9COmtQ0+sqrwxwjiJf1yuyuGXUy3DpUX5f9/M2BUfQXP7389NjK3YiQWSluc= om@rnd1

Проверяем. На машине клиенте:
root@rnd1 # ssh -l om 10.10.0.165
Last login: Sat Aug 29 10:34:13 2009 from 10.10.0.179
Sun Microsystems Inc. SunOS 5.9 Generic May 2002
bash-2.05$

Готово.

Теперь для Windows. Я пользуюсь ssh клиентом putty. На мой взгляд самая удобная прога. Ходят слухи, что она некорректно работает с serial портом, но я такого не замечал. Для того, чтобы сгенерить пару ключей нам понадобится программа puttygen.exe. Гуглим, качаем, ставим.

Для того, чтобы сгенерился ключ нужно поводить мишой по окну программы для генерации random.


Система таже самая. public ключ прописываем на Unix сервере, на который будем заходить без пароля. В папке пользователя заходим в .ssh, в ней создаем authorized_keys. Вставляем строчку с public ключем.
Теперь создаём сессию в putty. Вбиваем ip адрес сервера или доменное имя. Заполняем имя пользователя в Session - Connection - Data (Auto-login username). Далее Session - Connection - SSH - Auth в поле Authentication parameters ставим галку на Allow agent forwarding. Ниже в поле Key грузим наш public ключ. Не забываем сохранить сессию. Проверяем.

Using username "om".
Authenticating with public key "rsa-key-20090828"
Last login: Fri Aug 28 15:26:14 2009 from 10.10.0.101
bash-2.05$ id
uid=1001(om) gid=1(other)
bash-2.05$

Вот так.