author | Oleksandr Gavenko <gavenkoa@gmail.com> |
Sat, 10 Feb 2018 01:28:53 +0200 | |
changeset 2227 | 1e9323e7ec88 |
parent 1957 | cd6f239a8dd3 |
child 2228 | 837f1337c59b |
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 |
===================== |
|
1957
cd6f239a8dd3
Check available key types.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1956
diff
changeset
|
17 |
|
cd6f239a8dd3
Check available key types.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1956
diff
changeset
|
18 |
Check available key types:: |
cd6f239a8dd3
Check available key types.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1956
diff
changeset
|
19 |
|
cd6f239a8dd3
Check available key types.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1956
diff
changeset
|
20 |
$ ssh -Q key |
cd6f239a8dd3
Check available key types.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1956
diff
changeset
|
21 |
|
cd6f239a8dd3
Check available key types.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1956
diff
changeset
|
22 |
Generate keys:: |
1002 | 23 |
|
24 |
$ ssh-keygen -t dsa # for DSA |
|
25 |
$ ssh-keygen -t rsa # for RSA |
|
26 |
$ ssh-keygen -t dsa -C comment # put own comment instead user@host |
|
27 |
$ ssh-keygen -t dsa -f my_dsa_key # store priv key under my_dsa_key |
|
28 |
# and pub key under my_dsa_key.pub |
|
29 |
||
1626
73fa021859e7
recover pub key from priv
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1595
diff
changeset
|
30 |
$ ssh-keygen -y -f ~/.ssh/id_dsa >~/.ssh/id_dsa.pub # recover pub key from priv |
1002 | 31 |
|
32 |
$ ssh-keygen -p -N "newphrase" -P "oldphrase" -f ~/.ssh/id_dsa |
|
33 |
# change passphrase of priv key |
|
34 |
||
1858
c6dc48292ee8
Coping and deleting public keys.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1680
diff
changeset
|
35 |
Coping and deleting public keys. |
c6dc48292ee8
Coping and deleting public keys.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1680
diff
changeset
|
36 |
================================ |
c6dc48292ee8
Coping and deleting public keys.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1680
diff
changeset
|
37 |
|
c6dc48292ee8
Coping and deleting public keys.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1680
diff
changeset
|
38 |
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
|
39 |
authentication):: |
c6dc48292ee8
Coping and deleting public keys.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1680
diff
changeset
|
40 |
|
1002 | 41 |
$ ssh $user@$host cat ">>" "~/.ssh/authorized_keys" <~/.ssh/id_rsa.pub |
42 |
# public pub key on remote host |
|
43 |
||
1595 | 44 |
$ ssh-copy-id $user@$host # alternative to previous command |
45 |
||
1858
c6dc48292ee8
Coping and deleting public keys.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1680
diff
changeset
|
46 |
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
|
47 |
change server):: |
c6dc48292ee8
Coping and deleting public keys.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1680
diff
changeset
|
48 |
|
c6dc48292ee8
Coping and deleting public keys.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1680
diff
changeset
|
49 |
$ ssh-keygen -R hostname |
c6dc48292ee8
Coping and deleting public keys.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1680
diff
changeset
|
50 |
$ ssh-keygen -R hostname -f ~/.ssh/known_hosts |
c6dc48292ee8
Coping and deleting public keys.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1680
diff
changeset
|
51 |
|
1002 | 52 |
Shell login. |
53 |
============ |
|
54 |
:: |
|
55 |
||
56 |
$ ssh $user@$host |
|
57 |
$ ssh $user@$host:$port |
|
58 |
||
59 |
$ ssh -i ~/.ssh/my_dsa_key $user@$host |
|
60 |
||
61 |
or:: |
|
62 |
||
63 |
$ ssh -l $user $host |
|
64 |
$ ssh -l $user $host:$port |
|
65 |
||
1384 | 66 |
X11 forwarding. |
67 |
=============== |
|
68 |
||
69 |
Enable X11 forwarding on remote host in ``~/.ssh/config`` or ``/etc/ssh_config``:: |
|
70 |
||
71 |
X11Forwarding yes |
|
72 |
||
73 |
then login to this host by:: |
|
1002 | 74 |
|
75 |
$ ssh -X $user@$host |
|
76 |
||
1384 | 77 |
or by using trusted X11 forwarding:: |
78 |
||
79 |
$ ssh -Y $user@$host |
|
80 |
||
1386
864237ce5f1b
X11Forwarding does not work with OpenSSH under Cygwin
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1385
diff
changeset
|
81 |
See: |
864237ce5f1b
X11Forwarding does not work with OpenSSH under Cygwin
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1385
diff
changeset
|
82 |
|
864237ce5f1b
X11Forwarding does not work with OpenSSH under Cygwin
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1385
diff
changeset
|
83 |
http://x.cygwin.com/docs/faq/cygwin-x-faq.html#q-ssh-no-x11forwarding |
1904 | 84 |
X11Forwarding does not work with OpenSSH under Cygwin |
1384 | 85 |
|
1002 | 86 |
Multiply private keys. |
87 |
====================== |
|
88 |
||
89 |
ssh try use all listen keys:: |
|
90 |
||
91 |
$ ssh -i ./priv1 -i ./priv2 $user@$host |
|
92 |
||
93 |
or place in ~/.ssh/config:: |
|
94 |
||
95 |
Host * |
|
96 |
IdentityFile ~/.ssh/identity # standard search path for protocol ver. 1 |
|
97 |
IdentityFile ~/.ssh/id_dsa # standard search path for RSA key protocol ver. 2 |
|
98 |
IdentityFile ~/.ssh/id_rsa # standard search path for DSA key protocol ver. 2 |
|
99 |
IdentityFile ~/.ssh/my_dsa |
|
100 |
IdentityFile ~/.ssh/another_dsa |
|
101 |
||
102 |
or per host private key:: |
|
103 |
||
104 |
Host host1 # alias, that user provide at CLI |
|
105 |
HostName host1.example.com # real host name to log into |
|
106 |
User iam |
|
107 |
IdentifyFile ~/.ssh/iam_priv_dsa |
|
108 |
Host host2 # alias, that user provide at CLI |
|
109 |
HostName 192.168.1.2 # real host IP to log into |
|
110 |
User admin |
|
111 |
IdentifyFile ~/.ssh/admin_priv_dsa |
|
112 |
||
113 |
Installing sshd on Cygwin. |
|
114 |
========================== |
|
115 |
||
1904 | 116 |
* Install base packages and openssh. |
1954
307ce848ea6a
Update instruction for sshd under Cygwin.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
117 |
* Create Windows user and set its password. |
1904 | 118 |
* Recreate /etc/passwd:: |
119 |
||
120 |
$ mkpasswd -l -u user >>/etc/passwd |
|
121 |
||
122 |
or:: |
|
123 |
||
124 |
$ mkpasswd -l >/etc/passwd |
|
125 |
||
126 |
* Register sshd:: |
|
1002 | 127 |
|
1904 | 128 |
$ mkdir -p /home/user |
129 |
$ ssh-host-config -y |
|
130 |
||
131 |
* Start:: |
|
132 |
||
133 |
$ net start sshd |
|
1002 | 134 |
|
1904 | 135 |
or:: |
136 |
||
137 |
$ cygrunsrv -S sshd |
|
138 |
||
139 |
* Check from remote host:: |
|
140 |
||
141 |
$ ssh $gygwin_host -l user |
|
1002 | 142 |
|
143 |
To stop service use:: |
|
144 |
||
145 |
$ net stop sshd |
|
1680
826133768ee5
connection closed fix.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1626
diff
changeset
|
146 |
$ cygrunsrv -E sshd |
1002 | 147 |
|
1954
307ce848ea6a
Update instruction for sshd under Cygwin.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
148 |
To delete service:: |
307ce848ea6a
Update instruction for sshd under Cygwin.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
149 |
|
307ce848ea6a
Update instruction for sshd under Cygwin.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
150 |
$ cygrunsrv -E sshd |
307ce848ea6a
Update instruction for sshd under Cygwin.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
151 |
$ cygrunsrv -R sshd |
307ce848ea6a
Update instruction for sshd under Cygwin.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
152 |
|
1680
826133768ee5
connection closed fix.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1626
diff
changeset
|
153 |
If you have ``connection closed`` error check permission for ``/home/*/.ssh`` |
826133768ee5
connection closed fix.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1626
diff
changeset
|
154 |
directories. If you start service from ``user`` account - add write permission |
826133768ee5
connection closed fix.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1626
diff
changeset
|
155 |
to ``/home/*/.ssh``. I fix by:: |
1002 | 156 |
|
1680
826133768ee5
connection closed fix.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1626
diff
changeset
|
157 |
$ rm -r /home/*/.ssh |
826133768ee5
connection closed fix.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1626
diff
changeset
|
158 |
cmd> icacls c:\opt\cygwin\home /t /grant:r cyg_server:(f) |
1002 | 159 |
|
1954
307ce848ea6a
Update instruction for sshd under Cygwin.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
160 |
In order to enable logging from ``sshd`` uncomment in ``/etc/ssh/sshd_config``:: |
1002 | 161 |
|
1954
307ce848ea6a
Update instruction for sshd under Cygwin.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
162 |
SyslogFacility AUTH |
307ce848ea6a
Update instruction for sshd under Cygwin.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
163 |
LogLevel INFO |
1002 | 164 |
|
1954
307ce848ea6a
Update instruction for sshd under Cygwin.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
165 |
and start syslogd from ``inetutils`` package (don't forget to restart |
307ce848ea6a
Update instruction for sshd under Cygwin.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
166 |
``sshd``!):: |
1002 | 167 |
|
1954
307ce848ea6a
Update instruction for sshd under Cygwin.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
168 |
$ /bin/syslogd-config |
307ce848ea6a
Update instruction for sshd under Cygwin.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
169 |
$ net start syslogd |
1002 | 170 |
|
1954
307ce848ea6a
Update instruction for sshd under Cygwin.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
171 |
Check ``/var/log/messages`` for logging messages. |
1955
62735335fcef
userauth_pubkey: key type ssh-dss not in PubkeyAcceptedKeyTypes
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1954
diff
changeset
|
172 |
|
62735335fcef
userauth_pubkey: key type ssh-dss not in PubkeyAcceptedKeyTypes
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1954
diff
changeset
|
173 |
.. note:: |
62735335fcef
userauth_pubkey: key type ssh-dss not in PubkeyAcceptedKeyTypes
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1954
diff
changeset
|
174 |
|
62735335fcef
userauth_pubkey: key type ssh-dss not in PubkeyAcceptedKeyTypes
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1954
diff
changeset
|
175 |
In order to allow pubkey login and to avoid error:: |
62735335fcef
userauth_pubkey: key type ssh-dss not in PubkeyAcceptedKeyTypes
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1954
diff
changeset
|
176 |
|
62735335fcef
userauth_pubkey: key type ssh-dss not in PubkeyAcceptedKeyTypes
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1954
diff
changeset
|
177 |
userauth_pubkey: key type ssh-dss not in PubkeyAcceptedKeyTypes |
62735335fcef
userauth_pubkey: key type ssh-dss not in PubkeyAcceptedKeyTypes
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1954
diff
changeset
|
178 |
|
1956
5f39abb7d5b0
DSS keys are depricated at all
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1955
diff
changeset
|
179 |
add ``PubkeyAcceptedKeyTypes *`` or ``PubkeyAcceptedKeyTypes=+ssh-dss`` to |
5f39abb7d5b0
DSS keys are depricated at all
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1955
diff
changeset
|
180 |
``/etc/ssh/sshd_config`` but DSS keys are depricated at all. |
1955
62735335fcef
userauth_pubkey: key type ssh-dss not in PubkeyAcceptedKeyTypes
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1954
diff
changeset
|
181 |