Ssh Clientseite: Unterschied zwischen den Versionen

Aus Xinux Wiki
Zur Navigation springen Zur Suche springen
 
(56 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 1: Zeile 1:
 +
=Erster Verbindungsaufbau=
 +
:alice@u3:~$ ssh bob@u2
 +
The authenticity of host 'u2 (172.16.10.2)' can't be established.
 +
ECDSA key fingerprint is SHA256:Dp+DL5apc0A3rsUKCPcvbLSBmb4BSQXDsJGLJR0r0GA.
 +
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
 +
:bob@u2's password:
 +
:bob@u2:~$
 +
=Exit=
 +
:bob@u2:~$ exit
 +
:alice@u3:~$ cat .ssh/known_hosts
 +
<pre>
 +
|1|5BdpwWv6AjvkrERbWPK0NCdeWiY=|XEQyvQ0nw5bIIM7UHd6rbJwIA1A= ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBNmNwRv2mqfgV3SwvASy48CIjb4oSmxqcQf7e28dCYQxGRfIXiQK5HYKagkqsfBgai+iIiLKDrkav7tvqX0XsAQ=
 +
|1|m9IwDx96MLYRVu8WE49HjWRcdyk=|CVTp1yv65aqMW6Y1zWngj0j1oW8= ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBNmNwRv2mqfgV3SwvASy48CIjb4oSmxqcQf7e28dCYQxGRfIXiQK5HYKagkqsfBgai+iIiLKDrkav7tvqX0XsAQ=
 +
</pre>
 +
:Der Publikkey des Server '''u3''' wurde hinzugefügt
 +
=Befehl ausführen=
 +
:alice@u3:~$ ssh bob@u2 hostname
 +
:bob@u2's password:
 +
u2
  
=Clientseite=
+
=alternativer Aufruf=
*ssh (OpenSSH client) ist ein Programm um auf einen entfernten Rechner zuzugreifen und dort Kommandos auszuführen.
+
:alice@u3:~$ ssh -l bob u2
*Es ersetzt die Programme rlogin und rsh und stellt eine sichere verschlüsselte Verbindung zwischen zwei Rechnern her.  
+
:bob@u2's password:
*ssh verbindet sich mit dem Zielrechner, worauf der Benutzer seine Identität über verschiedene Methoden nachweisen muss.  
+
:bob@u2:~$
=Aufruf=
+
=Angabe eines speziellen Ports=
*ssh [Optionen] Benutzer@Zielrechner [Kommando]
+
:alice@u3:~$ ssh -p 8822 -l bob u2
;Wenn ein Kommando angegeben wird, wird dieses anstelle der Login-Shell ausgeführt.
+
:bob@u2's password:
 +
:bob@u2:~$
 +
=Schlüsselpaar erzeugen=
 +
:alice@u3:~$ ssh-keygen  -b 4096
 +
;Alternativ
 +
:ssh-keygen -t ed25519
 +
<pre>
 +
Generating public/private rsa key pair.
 +
Enter file in which to save the key (/home/alice/.ssh/id_rsa):
 +
Enter passphrase (empty for no passphrase):
 +
Enter same passphrase again:
 +
Your identification has been saved in /home/alice/.ssh/id_rsa
 +
Your public key has been saved in /home/alice/.ssh/id_rsa.pub
 +
The key fingerprint is:
 +
SHA256:PrjyG7hdgYyB8o3G6AylcbWvmPjjJr29l4yGS7uAR44 alice@u3
 +
The key's randomart image is:
 +
+---[RSA 4096]----+
 +
|    .            |
 +
|  o .          |
 +
|o + o            |
 +
| X o = .        |
 +
|+ * o + S        |
 +
|=* o o o .       |
 +
|E+*.ooo.+        |
 +
|.==o+o++ .      |
 +
| +B*+==.        |
 +
+----[SHA256]-----+
 +
</pre>
  
===Optionen===
+
=Schlüsselpaar=
* -1 : Erzwingt die ausschließliche Benutzung von ssh Protokollversion 1
+
*Wir haben nun ein Schlüsselpaar erzeugt.
* -2 : Erzwingt die ausschließliche Benutzung von ssh Protokollversion 2
+
*Der geheime Schlüssel ist passwort-geschützt.
* -4 : Erzwingt die ausschließliche Benutzung von IPv4 Adressen
+
*Dieses Passwort wird beim erstmaligen Nutzen nach dem Einloggen abgefragt.
* -6 : Erzwingt die ausschließliche Benutzung von IPv6 Adressen
+
*Danach befindet sich der geheime Schlüssel im Arbeitsspeicher.
* -b ''Quelladresse'' : Benutzt die ''Quelladresse'' als Ursprung für die Verbindung. Nur nützlich bei Systemen mit
+
*Er wird von dem SSH-Agent verwaltet.
mehreren (IP-)Adressen
+
=Das Schlüsselpaar=
* -C : Aktiviert Kompression falls möglich. Dies ist für langsame Verbindungen (z.B. über 56k Modem) gedacht und
+
:alice@u3:~$ ls  .ssh/id_rsa*
würde schnelle Netzwerke verlangsamen
+
.ssh/id_rsa  .ssh/id_rsa.pub
* -l ''Benutzer'' : Gibt ''Benutzer'' an, alternativ zu ''Benutzer''@Zielrechner
+
=Übertragen des Publik Keys zu bob@u2=
* -p ''port'' : Gibt Zielport an
+
:alice@u3:~$ ssh-copy-id bob@u2
* -V : Zeigt die Versionsnummer an
+
<pre>
* -v : ausführliche Ausgabe
+
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/alice/.ssh/id_rsa.pub"
* -X : Erlaubt X11 forwarding, damit können entfernte Programme mit grafischen Benutzerinterface (GUI) lokal angezeigt werden
+
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
* -x : Verbietet X11 forwarding
+
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
 +
bob@u2's password:  
  
Beispiele
+
Number of key(s) added: 1
  
Zugriff auf einen bisher unbekannten Zielrechner
+
Now try logging into the machine, with:   "ssh 'bob@u2'"
root@zero:~# ssh root@alita
+
and check to make sure that only the key(s) you wanted were added.
The authenticity of host 'alita (192.168.242.10)' can't be established.
+
</pre>
RSA key fingerprint is 8c:d1:1f:d2:5e:76:cd:75:74:c4:b7:b2:c7:f6:50:78.
+
=Alternatives Übertragen des Publik Keys zu bob@u2=
Are you sure you want to continue connecting (yes/no)? yes
+
:alice@u3:~$ scp ~/.ssh/id_*.pub bob@u2:~
  Warning: Permanently added 'alita,192.168.242.10' (RSA) to the list of known hosts.
+
:alice@u3:~$ ssh bob@u2
root@alita's password: Passwort_das_nicht_angezeigt_wird
+
:bob@u2:~$ cat id_*.pub >> .ssh/authorized_keys
...
 
root@alita:~#
 
Um die Identität des Zielrechners zu verifizieren, kann man den den Fingerprint des öffentlichen RSA Schlüssels
 
auf der Serverseite ausgeben lassen. Dieser kann dann mit dem oben angezeigten verglichen werden.  
 
  
Zugriff auf bekannten Zielrechner
+
=Der Private Key ist noch nicht im Arbeitsspeicher=
root@zero:~# ssh alita
+
:alice@u3:~$ ssh-add -l
  root@alita's password: Passwort_das_nicht_angezeigt_wird
+
  The agent has no identities.
  ...
+
=Wir fügen den Private Key zum Agent hinzu=
  root@alita:~#
+
:alice@u3:~$ ssh-add
 +
  Enter passphrase for /home/alice/.ssh/id_rsa:
 +
  Identity added: /home/alice/.ssh/id_rsa (alice@u3)
  
Zugriff als Benutzer christian und auf Port 9998
+
=Der Private Key ist nun im Arbeitsspeicher und wird vom Agent verwaltet=
root@zero:~# ssh alita -l christian -p 9998
+
:alice@u3:~$ ssh-add -l
  christian@alita's password: Passwort_das_nicht_angezeigt_wird
+
  4096 SHA256:PrjyG7hdgYyB8o3G6AylcbWvmPjjJr29l4yGS7uAR44 alice@u3 (RSA)
...
+
=Einlogen ohne Passwort=
  christian@alita:~$
+
:alice@u3:~$ ssh bob@u2
 +
  bob@u2:~$
  
Ausführen eines Kommandos auf dem Zielrechner
+
=Einloggen ohne Passwort=
root@zero:~# ssh alita cat /etc/hostname
+
:alice@u3:~$ ssh bob@u2
root@alita's password:
+
<pre>
alita
+
Enter passphrase for key '/home/alice/.ssh/id_rsa':
root@zero:~#
+
bob@u2:~$
 +
</pre>
 +
=Wir bringen nun den Public-Key von alice auf den Account bob@u1=
 +
:alice@u3:~$ ssh-copy-id bob@u1
 +
<pre>
 +
The authenticity of host 'u1 (172.16.10.1)' can't be established.
 +
ECDSA key fingerprint is SHA256:Dp+DL5apc0A3rsUKCPcvbLSBmb4BSQXDsJGLJR0r0GA.
 +
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
 +
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
 +
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
 +
</pre>
 +
:bob@u1's password:  
 +
<pre>
 +
Number of key(s) added: 1
  
Ausführen eines grafischen Programms auf dem Zielrechner und lokal anzeigen
+
Now try logging into the machine, with:  "ssh 'bob@u1'"
  root@zero:~# ssh -X root@alita kate
+
and check to make sure that only the key(s) you wanted were added.
 +
</pre>
 +
:alice@u3:~$
 +
=Einloggen=
 +
:alice@u3:~$ ssh  bob@u2
 +
:bob@u2:~$
 +
;Wir haben den Schlüssel mit genommen.
 +
:bob@u2:~$ ssh-add  -l
 +
  4096 SHA256:PrjyG7hdgYyB8o3G6AylcbWvmPjjJr29l4yGS7uAR44 alice@u3 (RSA)
 +
:bob@u2:~$ ssh -A u1
 +
:bob@u1:~$
 +
;Wir haben den Schlüssel weiter mit genommen.
 +
:bob@u1:~$ ssh-add  -l
 +
4096 SHA256:PrjyG7hdgYyB8o3G6AylcbWvmPjjJr29l4yGS7uAR44 alice@u3 (RSA)
  
[[Image:kate.jpg]]
+
=Cipher mit angeben=
 +
:alice@u3:~$ ssh -o kexalgorithms=diffie-hellman-group-exchange-sha1  -o HostKeyAlgorithms=+ssh-rsa -o  Ciphers=+3des-cbc  10.10.4.108 -l xinux -p 22
  
===Authentifizierung mit Schlüssel===
+
=Beispiel der User Konfigurationsdatei=
====Schlüsselpaar erstellen====
+
~/.ssh/config
xinux@zero:~$ ssh-keygen
+
<pre>
Generating public/private rsa key pair.
+
  host github.com
Enter file in which to save the key (/home/xinux/.ssh/id_rsa):
+
  Port 22
Enter passphrase (empty for no passphrase):
 
Enter same passphrase again:
 
Your identification has been saved in /home/xinux/.ssh/id_rsa.
 
  Your public key has been saved in /home/xinux/.ssh/id_rsa.pub.
 
The key fingerprint is:
 
a7:13:ec:54:a3:4f:29:32:f8:98:04:ea:0c:b9:62:04 xinux@zero
 
The key's randomart image is:
 
+--[ RSA 2048]----+
 
|                |
 
|                |
 
|E .      o      |
 
|.o . . . o o    |
 
|+.  o o S +      |
 
|=. . + = B      |
 
|o+  o . + .      |
 
|o        .      |
 
|                |
 
+-----------------+
 
xinux@zero:~$
 
  
====Übertragen des öffentlichen Schlüssels====
+
host 10.81.0.12
=====Ubuntu=====
+
user admin
  xinux@zero:~$ ssh-copy-id -i .ssh/'''id_rsa.pub''' root@alita
+
ciphers aes128-cbc
  root@alita's password: Passwort_das_nicht_angezeigt_wird
+
  KexAlgorithms +diffie-hellman-group1-sha1
Now try logging into the machine, with "ssh 'root@alita'", and check in:
+
  HostKeyAlgorithms=+ssh-rsa
   
+
  port 22
  .ssh/authorized_keys
+
</pre>
 
to make sure we haven't added extra keys that you weren't expecting.
 
 
xinux@zero:~$
 
  
=====ESXI=====
+
=SSH Optionen=
xinux@zero:~$ cat .ssh/id_rsa.pub | ssh root@esxi \
+
*[[Ausgewählte SSH Optionen]]
'cat >> /etc/ssh/keys-root/authorized_keys'
 
 
 
====Einloggen auf Remoterechner====
 
root@zero:~# ssh root@alita
 
Linux alita 2.6.28-13-generic #44-Ubuntu SMP Tue Jun 2 07:57:31 UTC 2009 i686
 
 
The programs included with the Ubuntu system are free software;
 
the exact distribution terms for each program are described in the
 
individual files in /usr/share/doc/*/copyright.
 
 
Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
 
applicable law.
 
 
To access official Ubuntu documentation, please visit:
 
http://help.ubuntu.com/
 
 
0 packages can be updated.
 
0 updates are security updates.
 
 
Last login: Thu Jul  2 13:54:13 2009 from zero.alpha.quadrant
 
root@alita:~#
 
 
 
 
 
===scp secure copy===
 
scp steht für Secure Copy und ermöglicht es, Dateien in einem Netzwerk zu kopieren. Es baut auf ssh auf und benutzt
 
entsprechend Authentifizierung und Verschlüsselung.
 
 
 
scp [Optionen] Benutzer@Rechner1:/Pfad/zu/Datei lokaler_Dateipfad
 
scp [Optionen] lokaler Dateipfad Benutzer@Rechner2:/Pfad/zu/Datei2
 
 
 
====Optionen====
 
* -1 : Erzwingt die ausschließliche Benutzung von ssh Protokollversion 1
 
* -2 : Erzwingt die ausschließliche Benutzung von ssh Protokollversion 2
 
* -4 : Erzwingt die ausschließliche Benutzung von IPv4 Adressen
 
* -6 : Erzwingt die ausschließliche Benutzung von IPv6 Adressen
 
* -C : Benutzt Komprimierung
 
* -P port: Benutzt Port auf dem Zielrechner; Achtung: großes P!
 
* -p : Verändert nicht die Zeiten der letzten Veränderung der Datei
 
* -r : rekursives Kopieren; scp folgt dabei auch symbolischen Links
 
* -v : ausführliche Ausgabe
 
 
 
 
 
Beispiele
 
 
 
Kopieren aller Dateien und Verzeinissen von einem lokalen Verzeichnis in ein entferntes Verzeichnis
 
root@zero:~# scp -r /etc/* root@alita:/tmp/
 
root@alita's password:
 
powerbtn.sh                                100%  517    0.5KB/s  00:00
 
...
 
 
 
Kopieren eines entfernten Verzeichnisses in ein lokales Verzeichnis
 
root@zero:~# scp -r root@alita:/root /root/alita_backup/
 
root@alita's password:   
 
.bashrc                                      100% 2227    2.2KB/s  00:00 
 
...
 
 
 
=vpn-pppd ssh Tunnelscript=
 
 
ssh nagus
 
cat /usr/local/sbin/vpn-pppd
 
 
 
=enable diffie-hellman-group1-sha1 key exchange=
 
mit dem direkten befehl:
 
 
 
*ssh -oKexAlgorithms=+diffie-hellman-group1-sha1 123.123.123.123
 
 
 
dauerhaft eintragen:
 
 
 
* /etc/ssh/ssh_config
 
<pre>
 
Host 123.123.123.123
 
    KexAlgorithms +diffie-hellman-group1-sha1
 
</pre>
 

Aktuelle Version vom 30. Juli 2024, 09:26 Uhr

Erster Verbindungsaufbau

alice@u3:~$ ssh bob@u2
The authenticity of host 'u2 (172.16.10.2)' can't be established.
ECDSA key fingerprint is SHA256:Dp+DL5apc0A3rsUKCPcvbLSBmb4BSQXDsJGLJR0r0GA.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
bob@u2's password:
bob@u2:~$

Exit

bob@u2:~$ exit
alice@u3:~$ cat .ssh/known_hosts
|1|5BdpwWv6AjvkrERbWPK0NCdeWiY=|XEQyvQ0nw5bIIM7UHd6rbJwIA1A= ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBNmNwRv2mqfgV3SwvASy48CIjb4oSmxqcQf7e28dCYQxGRfIXiQK5HYKagkqsfBgai+iIiLKDrkav7tvqX0XsAQ=
|1|m9IwDx96MLYRVu8WE49HjWRcdyk=|CVTp1yv65aqMW6Y1zWngj0j1oW8= ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBNmNwRv2mqfgV3SwvASy48CIjb4oSmxqcQf7e28dCYQxGRfIXiQK5HYKagkqsfBgai+iIiLKDrkav7tvqX0XsAQ=
Der Publikkey des Server u3 wurde hinzugefügt

Befehl ausführen

alice@u3:~$ ssh bob@u2 hostname
bob@u2's password:
u2

alternativer Aufruf

alice@u3:~$ ssh -l bob u2
bob@u2's password:
bob@u2:~$

Angabe eines speziellen Ports

alice@u3:~$ ssh -p 8822 -l bob u2
bob@u2's password:
bob@u2:~$

Schlüsselpaar erzeugen

alice@u3:~$ ssh-keygen -b 4096
Alternativ
ssh-keygen -t ed25519
Generating public/private rsa key pair.
Enter file in which to save the key (/home/alice/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/alice/.ssh/id_rsa
Your public key has been saved in /home/alice/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:PrjyG7hdgYyB8o3G6AylcbWvmPjjJr29l4yGS7uAR44 alice@u3
The key's randomart image is:
+---[RSA 4096]----+
|    .            |
|   o .           |
|o + o            |
| X o = .         |
|+ * o + S        |
|=* o o o .       |
|E+*.ooo.+        |
|.==o+o++ .       |
| +B*+==.         |
+----[SHA256]-----+

Schlüsselpaar

  • Wir haben nun ein Schlüsselpaar erzeugt.
  • Der geheime Schlüssel ist passwort-geschützt.
  • Dieses Passwort wird beim erstmaligen Nutzen nach dem Einloggen abgefragt.
  • Danach befindet sich der geheime Schlüssel im Arbeitsspeicher.
  • Er wird von dem SSH-Agent verwaltet.

Das Schlüsselpaar

alice@u3:~$ ls .ssh/id_rsa*
.ssh/id_rsa  .ssh/id_rsa.pub

Übertragen des Publik Keys zu bob@u2

alice@u3:~$ ssh-copy-id bob@u2
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/alice/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
bob@u2's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'bob@u2'"
and check to make sure that only the key(s) you wanted were added.

Alternatives Übertragen des Publik Keys zu bob@u2

alice@u3:~$ scp ~/.ssh/id_*.pub bob@u2:~
alice@u3:~$ ssh bob@u2
bob@u2:~$ cat id_*.pub >> .ssh/authorized_keys

Der Private Key ist noch nicht im Arbeitsspeicher

alice@u3:~$ ssh-add -l
The agent has no identities.

Wir fügen den Private Key zum Agent hinzu

alice@u3:~$ ssh-add
Enter passphrase for /home/alice/.ssh/id_rsa: 
Identity added: /home/alice/.ssh/id_rsa (alice@u3)

Der Private Key ist nun im Arbeitsspeicher und wird vom Agent verwaltet

alice@u3:~$ ssh-add -l
4096 SHA256:PrjyG7hdgYyB8o3G6AylcbWvmPjjJr29l4yGS7uAR44 alice@u3 (RSA)

Einlogen ohne Passwort

alice@u3:~$ ssh bob@u2
bob@u2:~$

Einloggen ohne Passwort

alice@u3:~$ ssh bob@u2
Enter passphrase for key '/home/alice/.ssh/id_rsa': 
bob@u2:~$ 

Wir bringen nun den Public-Key von alice auf den Account bob@u1

alice@u3:~$ ssh-copy-id bob@u1
The authenticity of host 'u1 (172.16.10.1)' can't be established.
ECDSA key fingerprint is SHA256:Dp+DL5apc0A3rsUKCPcvbLSBmb4BSQXDsJGLJR0r0GA.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
bob@u1's password:
Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'bob@u1'"
and check to make sure that only the key(s) you wanted were added.
alice@u3:~$

Einloggen

alice@u3:~$ ssh bob@u2
bob@u2:~$
Wir haben den Schlüssel mit genommen.
bob@u2:~$ ssh-add -l
4096 SHA256:PrjyG7hdgYyB8o3G6AylcbWvmPjjJr29l4yGS7uAR44 alice@u3 (RSA)
bob@u2:~$ ssh -A u1
bob@u1:~$
Wir haben den Schlüssel weiter mit genommen.
bob@u1:~$ ssh-add -l
4096 SHA256:PrjyG7hdgYyB8o3G6AylcbWvmPjjJr29l4yGS7uAR44 alice@u3 (RSA)

Cipher mit angeben

alice@u3:~$ ssh -o kexalgorithms=diffie-hellman-group-exchange-sha1 -o HostKeyAlgorithms=+ssh-rsa -o Ciphers=+3des-cbc 10.10.4.108 -l xinux -p 22

Beispiel der User Konfigurationsdatei

~/.ssh/config

 
 host github.com
  Port 22

host 10.81.0.12
 user admin 
 ciphers aes128-cbc
 KexAlgorithms +diffie-hellman-group1-sha1
 HostKeyAlgorithms=+ssh-rsa
 port 22

SSH Optionen