author | Oleksandr Gavenko <gavenkoa@gmail.com> |
Sun, 28 Feb 2016 14:50:39 +0200 | |
changeset 1929 | 3ce74b5f43c9 |
parent 1912 | 8b81a8f0f692 |
child 1954 | 307ce848ea6a |
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; -*- |
1002 | 2 |
|
3 |
=========== |
|
4 |
SSH/sshd. |
|
5 |
=========== |
|
1032
4decc3e00bb6
Fix coding and contents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1002
diff
changeset
|
6 |
.. contents:: |
1904 | 7 |
:local: |
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 |
||
1858
c6dc48292ee8
Coping and deleting public keys.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1680
diff
changeset
|
30 |
Coping and deleting public keys. |
c6dc48292ee8
Coping and deleting public keys.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1680
diff
changeset
|
31 |
================================ |
c6dc48292ee8
Coping and deleting public keys.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1680
diff
changeset
|
32 |
|
c6dc48292ee8
Coping and deleting public keys.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1680
diff
changeset
|
33 |
To copy your public key to remote host (for automatic login by pubkey |
c6dc48292ee8
Coping and deleting public keys.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1680
diff
changeset
|
34 |
authentication):: |
c6dc48292ee8
Coping and deleting public keys.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1680
diff
changeset
|
35 |
|
1002 | 36 |
$ ssh $user@$host cat ">>" "~/.ssh/authorized_keys" <~/.ssh/id_rsa.pub |
37 |
# public pub key on remote host |
|
38 |
||
1595 | 39 |
$ ssh-copy-id $user@$host # alternative to previous command |
40 |
||
1858
c6dc48292ee8
Coping and deleting public keys.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1680
diff
changeset
|
41 |
To remove ``known_hosts`` key (usually need if you change server pubkey or |
c6dc48292ee8
Coping and deleting public keys.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1680
diff
changeset
|
42 |
change server):: |
c6dc48292ee8
Coping and deleting public keys.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1680
diff
changeset
|
43 |
|
c6dc48292ee8
Coping and deleting public keys.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1680
diff
changeset
|
44 |
$ ssh-keygen -R hostname |
c6dc48292ee8
Coping and deleting public keys.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1680
diff
changeset
|
45 |
$ ssh-keygen -R hostname -f ~/.ssh/known_hosts |
c6dc48292ee8
Coping and deleting public keys.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1680
diff
changeset
|
46 |
|
1002 | 47 |
Shell login. |
48 |
============ |
|
49 |
:: |
|
50 |
||
51 |
$ ssh $user@$host |
|
52 |
$ ssh $user@$host:$port |
|
53 |
||
54 |
$ ssh -i ~/.ssh/my_dsa_key $user@$host |
|
55 |
||
56 |
or:: |
|
57 |
||
58 |
$ ssh -l $user $host |
|
59 |
$ ssh -l $user $host:$port |
|
60 |
||
1384 | 61 |
X11 forwarding. |
62 |
=============== |
|
63 |
||
64 |
Enable X11 forwarding on remote host in ``~/.ssh/config`` or ``/etc/ssh_config``:: |
|
65 |
||
66 |
X11Forwarding yes |
|
67 |
||
68 |
then login to this host by:: |
|
1002 | 69 |
|
70 |
$ ssh -X $user@$host |
|
71 |
||
1384 | 72 |
or by using trusted X11 forwarding:: |
73 |
||
74 |
$ ssh -Y $user@$host |
|
75 |
||
1386
864237ce5f1b
X11Forwarding does not work with OpenSSH under Cygwin
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1385
diff
changeset
|
76 |
See: |
864237ce5f1b
X11Forwarding does not work with OpenSSH under Cygwin
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1385
diff
changeset
|
77 |
|
864237ce5f1b
X11Forwarding does not work with OpenSSH under Cygwin
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1385
diff
changeset
|
78 |
http://x.cygwin.com/docs/faq/cygwin-x-faq.html#q-ssh-no-x11forwarding |
1904 | 79 |
X11Forwarding does not work with OpenSSH under Cygwin |
1384 | 80 |
|
1002 | 81 |
Multiply private keys. |
82 |
====================== |
|
83 |
||
84 |
ssh try use all listen keys:: |
|
85 |
||
86 |
$ ssh -i ./priv1 -i ./priv2 $user@$host |
|
87 |
||
88 |
or place in ~/.ssh/config:: |
|
89 |
||
90 |
Host * |
|
91 |
IdentityFile ~/.ssh/identity # standard search path for protocol ver. 1 |
|
92 |
IdentityFile ~/.ssh/id_dsa # standard search path for RSA key protocol ver. 2 |
|
93 |
IdentityFile ~/.ssh/id_rsa # standard search path for DSA key protocol ver. 2 |
|
94 |
IdentityFile ~/.ssh/my_dsa |
|
95 |
IdentityFile ~/.ssh/another_dsa |
|
96 |
||
97 |
or per host private key:: |
|
98 |
||
99 |
Host host1 # alias, that user provide at CLI |
|
100 |
HostName host1.example.com # real host name to log into |
|
101 |
User iam |
|
102 |
IdentifyFile ~/.ssh/iam_priv_dsa |
|
103 |
Host host2 # alias, that user provide at CLI |
|
104 |
HostName 192.168.1.2 # real host IP to log into |
|
105 |
User admin |
|
106 |
IdentifyFile ~/.ssh/admin_priv_dsa |
|
107 |
||
108 |
Installing sshd on Cygwin. |
|
109 |
========================== |
|
110 |
||
1904 | 111 |
* Install base packages and openssh. |
112 |
* Set CYGWIN env var to 'binmode ntsec'. |
|
113 |
* Create Windows user. |
|
114 |
* Recreate /etc/passwd:: |
|
115 |
||
116 |
$ mkpasswd -l -u user >>/etc/passwd |
|
117 |
||
118 |
or:: |
|
119 |
||
120 |
$ mkpasswd -l >/etc/passwd |
|
121 |
||
122 |
* Register sshd:: |
|
1002 | 123 |
|
1904 | 124 |
$ mkdir -p /home/user |
125 |
$ ssh-host-config -y |
|
126 |
||
127 |
* Start:: |
|
128 |
||
129 |
$ net start sshd |
|
1002 | 130 |
|
1904 | 131 |
or:: |
132 |
||
133 |
$ cygrunsrv -S sshd |
|
134 |
||
135 |
* Check from remote host:: |
|
136 |
||
137 |
$ ssh $gygwin_host -l user |
|
1002 | 138 |
|
139 |
To stop service use:: |
|
140 |
||
141 |
$ net stop sshd |
|
1680
826133768ee5
connection closed fix.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1626
diff
changeset
|
142 |
$ cygrunsrv -E sshd |
1002 | 143 |
|
1680
826133768ee5
connection closed fix.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1626
diff
changeset
|
144 |
If you have ``connection closed`` error check permission for ``/home/*/.ssh`` |
826133768ee5
connection closed fix.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1626
diff
changeset
|
145 |
directories. If you start service from ``user`` account - add write permission |
826133768ee5
connection closed fix.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1626
diff
changeset
|
146 |
to ``/home/*/.ssh``. I fix by:: |
1002 | 147 |
|
1680
826133768ee5
connection closed fix.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1626
diff
changeset
|
148 |
$ rm -r /home/*/.ssh |
826133768ee5
connection closed fix.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1626
diff
changeset
|
149 |
cmd> icacls c:\opt\cygwin\home /t /grant:r cyg_server:(f) |
1002 | 150 |
|
151 |
Запускаем SSH server на правах произвольного пользователя. |
|
152 |
---------------------------------------------------------- |
|
153 |
||
1904 | 154 |
* Создаем пользователя, например с именем user, задаем ему пароль, права (т.е. |
155 |
в какие группы будет входить) и т.д., пользователя не блокируем. |
|
156 |
* В консоле MMC добавляем оснастку "Параметры безопасности". Модифицируем |
|
157 |
параметры: |
|
1002 | 158 |
|
1383 | 159 |
"Параметры безопасности" --> "Локальные политики" --> "Назначение прав |
160 |
пользователя." --> "Вход в качестве службы" --> добавить 'user'. |
|
1002 | 161 |
|
1383 | 162 |
"Параметры безопасности" --> "Локальные политики" --> "Назначение прав |
163 |
пользователя" --> "Отклонить локальный вход" --> удалить 'user' (если был |
|
164 |
установлен). |
|
1002 | 165 |
|
1383 | 166 |
XXX "Принудительное удаленное завершение." |
1002 | 167 |