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