This document assumes that you are using OpenSSH on the client and remote computers
1.Create a public and private key pair for the protocol you want to use. To create a key pair for use by SSH2, enter: ssh-keygen
the key generation program will create a private key in a file with the name you specified and a public key with the same name, plus a.pub
extension.
2. Copy your public key to the remote host by entering:
scp ~/.ssh/filename.pub hostname:3. Connect to the remote host using your password for authentication. If the
authorized_keys
file doesn't exist, create it with the following commands:
mkdir -p ~/.ssh touch ~/.ssh/authorized_key
On the remote host, add your public key to theauthorized_keys
file, with the following command:
cat ~/filename.pub >> ~/.ssh/authorized_keys
Schritte 2 und 3 können auch mit dem Befehl
ssh-copy-id(z.b. ssh-copy-id amilo)
bequem zusammengefasst werden.To use
ssh-agent
andssh-add
, follow the steps below:
- At the Unix prompt, enter: eval $(ssh-agent)
- Enter the command: ssh-add
- Enter your private key password.
- When you log out, enter the command: kill $SSH_AGENT_PID To run this command automatically when you log out, place it in your
.logout
file (if you are usingcsh
ortcsh
) or your.bash_logout
file (if you are usingbash
).
trotz ssh-copy-id usf. werde ich immer noch aufgefordert, das Passwort einzugeben. Grund: Die Rechte von authorized-keys sind nicht richtig gesetzt. sshd achtet darauf, dass alle rechte so gesetzt sind, dass ein Angreifer diese Datei nicht verändern kann. Sind die Rechte zu lax gesetzt, weigert sich sshd, dieses Verfahren durchzuführen. Daher dürfen folgende Dateien nur für den Benutzer beschreibbar sein: .ssh/authorized-keys .ssh . Das Dritte Verzeichnis ist das home-Verzeichnis des Nutzers, sonst könnte ja ein Angfreifer einfach .ssh überschreiben.
Kommentare