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