author | Oleksandr Gavenko <gavenkoa@gmail.com> |
Mon, 19 Oct 2015 17:04:52 +0300 | |
changeset 1769 | cadd23f8127f |
parent 1680 | 826133768ee5 |
child 1858 | c6dc48292ee8 |
permissions | -rw-r--r-- |
1334
9bf0d5a1f0cf
Include common header with quick links.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1032
diff
changeset
|
1 |
.. -*- coding: utf-8; -*- |
9bf0d5a1f0cf
Include common header with quick links.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1032
diff
changeset
|
2 |
.. include:: HEADER.rst |
1002 | 3 |
|
4 |
=========== |
|
5 |
SSH/sshd. |
|
6 |
=========== |
|
1032
4decc3e00bb6
Fix coding and contents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1002
diff
changeset
|
7 |
.. contents:: |
1002 | 8 |
|
1385
acb36dfe5d09
Debugging ssh client.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1384
diff
changeset
|
9 |
Debugging ssh client. |
acb36dfe5d09
Debugging ssh client.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1384
diff
changeset
|
10 |
===================== |
acb36dfe5d09
Debugging ssh client.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1384
diff
changeset
|
11 |
:: |
acb36dfe5d09
Debugging ssh client.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1384
diff
changeset
|
12 |
|
acb36dfe5d09
Debugging ssh client.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1384
diff
changeset
|
13 |
$ ssh -vvv ... |
acb36dfe5d09
Debugging ssh client.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1384
diff
changeset
|
14 |
|
1002 | 15 |
Maintaining key pair. |
16 |
===================== |
|
17 |
:: |
|
18 |
||
19 |
$ ssh-keygen -t dsa # for DSA |
|
20 |
$ ssh-keygen -t rsa # for RSA |
|
21 |
$ ssh-keygen -t dsa -C comment # put own comment instead user@host |
|
22 |
$ ssh-keygen -t dsa -f my_dsa_key # store priv key under my_dsa_key |
|
23 |
# and pub key under my_dsa_key.pub |
|
24 |
||
1626
73fa021859e7
recover pub key from priv
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1595
diff
changeset
|
25 |
$ ssh-keygen -y -f ~/.ssh/id_dsa >~/.ssh/id_dsa.pub # recover pub key from priv |
1002 | 26 |
|
27 |
$ ssh-keygen -p -N "newphrase" -P "oldphrase" -f ~/.ssh/id_dsa |
|
28 |
# change passphrase of priv key |
|
29 |
||
30 |
$ ssh $user@$host cat ">>" "~/.ssh/authorized_keys" <~/.ssh/id_rsa.pub |
|
31 |
# public pub key on remote host |
|
32 |
||
1595 | 33 |
$ ssh-copy-id $user@$host # alternative to previous command |
34 |
||
1002 | 35 |
Shell login. |
36 |
============ |
|
37 |
:: |
|
38 |
||
39 |
$ ssh $user@$host |
|
40 |
$ ssh $user@$host:$port |
|
41 |
||
42 |
$ ssh -i ~/.ssh/my_dsa_key $user@$host |
|
43 |
||
44 |
or:: |
|
45 |
||
46 |
$ ssh -l $user $host |
|
47 |
$ ssh -l $user $host:$port |
|
48 |
||
1384 | 49 |
X11 forwarding. |
50 |
=============== |
|
51 |
||
52 |
Enable X11 forwarding on remote host in ``~/.ssh/config`` or ``/etc/ssh_config``:: |
|
53 |
||
54 |
X11Forwarding yes |
|
55 |
||
56 |
then login to this host by:: |
|
1002 | 57 |
|
58 |
$ ssh -X $user@$host |
|
59 |
||
1384 | 60 |
or by using trusted X11 forwarding:: |
61 |
||
62 |
$ ssh -Y $user@$host |
|
63 |
||
1386
864237ce5f1b
X11Forwarding does not work with OpenSSH under Cygwin
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1385
diff
changeset
|
64 |
See: |
864237ce5f1b
X11Forwarding does not work with OpenSSH under Cygwin
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1385
diff
changeset
|
65 |
|
864237ce5f1b
X11Forwarding does not work with OpenSSH under Cygwin
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1385
diff
changeset
|
66 |
http://x.cygwin.com/docs/faq/cygwin-x-faq.html#q-ssh-no-x11forwarding |
864237ce5f1b
X11Forwarding does not work with OpenSSH under Cygwin
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1385
diff
changeset
|
67 |
X11Forwarding does not work with OpenSSH under Cygwin |
1384 | 68 |
|
1002 | 69 |
Multiply private keys. |
70 |
====================== |
|
71 |
||
72 |
ssh try use all listen keys:: |
|
73 |
||
74 |
$ ssh -i ./priv1 -i ./priv2 $user@$host |
|
75 |
||
76 |
or place in ~/.ssh/config:: |
|
77 |
||
78 |
Host * |
|
79 |
IdentityFile ~/.ssh/identity # standard search path for protocol ver. 1 |
|
80 |
IdentityFile ~/.ssh/id_dsa # standard search path for RSA key protocol ver. 2 |
|
81 |
IdentityFile ~/.ssh/id_rsa # standard search path for DSA key protocol ver. 2 |
|
82 |
IdentityFile ~/.ssh/my_dsa |
|
83 |
IdentityFile ~/.ssh/another_dsa |
|
84 |
||
85 |
or per host private key:: |
|
86 |
||
87 |
Host host1 # alias, that user provide at CLI |
|
88 |
HostName host1.example.com # real host name to log into |
|
89 |
User iam |
|
90 |
IdentifyFile ~/.ssh/iam_priv_dsa |
|
91 |
Host host2 # alias, that user provide at CLI |
|
92 |
HostName 192.168.1.2 # real host IP to log into |
|
93 |
User admin |
|
94 |
IdentifyFile ~/.ssh/admin_priv_dsa |
|
95 |
||
96 |
Installing sshd on Cygwin. |
|
97 |
========================== |
|
98 |
||
99 |
* Install base packages and openssh. |
|
1382
9297a8f7e3f3
Fix: CYGWIN=tty is no longer supported.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1334
diff
changeset
|
100 |
* Set CYGWIN env var to 'binmode ntsec'. |
1002 | 101 |
* Create Windows user. |
102 |
* Recreate /etc/passwd:: |
|
103 |
$ mkpasswd -l -u user >>/etc/passwd |
|
104 |
or:: |
|
105 |
$ mkpasswd -l >/etc/passwd |
|
106 |
||
107 |
* Register sshd:: |
|
108 |
$ mkdir -p /home/user |
|
109 |
$ ssh-host-config -y |
|
110 |
* Start:: |
|
111 |
$ net start sshd |
|
112 |
or:: |
|
113 |
$ cygrunsrv -S sshd |
|
114 |
||
115 |
* Check from remote host:: |
|
116 |
$ ssh $gygwin_host -l user |
|
117 |
||
118 |
To stop service use:: |
|
119 |
||
120 |
$ net stop sshd |
|
1680
826133768ee5
connection closed fix.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1626
diff
changeset
|
121 |
$ cygrunsrv -E sshd |
1002 | 122 |
|
1680
826133768ee5
connection closed fix.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1626
diff
changeset
|
123 |
If you have ``connection closed`` error check permission for ``/home/*/.ssh`` |
826133768ee5
connection closed fix.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1626
diff
changeset
|
124 |
directories. If you start service from ``user`` account - add write permission |
826133768ee5
connection closed fix.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1626
diff
changeset
|
125 |
to ``/home/*/.ssh``. I fix by:: |
1002 | 126 |
|
1680
826133768ee5
connection closed fix.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1626
diff
changeset
|
127 |
$ rm -r /home/*/.ssh |
826133768ee5
connection closed fix.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1626
diff
changeset
|
128 |
cmd> icacls c:\opt\cygwin\home /t /grant:r cyg_server:(f) |
1002 | 129 |
|
130 |
Запускаем SSH server на правах произвольного пользователя. |
|
131 |
---------------------------------------------------------- |
|
132 |
||
1383 | 133 |
* Создаем пользователя, например с именем user, задаем ему пароль, права (т.е. |
134 |
в какие группы будет входить) и т.д., пользователя не блокируем. |
|
135 |
* В консоле MMC добавляем оснастку "Параметры безопасности". Модифицируем |
|
136 |
параметры: |
|
1002 | 137 |
|
1383 | 138 |
"Параметры безопасности" --> "Локальные политики" --> "Назначение прав |
139 |
пользователя." --> "Вход в качестве службы" --> добавить 'user'. |
|
1002 | 140 |
|
1383 | 141 |
"Параметры безопасности" --> "Локальные политики" --> "Назначение прав |
142 |
пользователя" --> "Отклонить локальный вход" --> удалить 'user' (если был |
|
143 |
установлен). |
|
1002 | 144 |
|
1383 | 145 |
XXX "Принудительное удаленное завершение." |
1002 | 146 |