Projekt

Allgemein

Profil

Setup ssh-rsalogin » Historie » Version 2

Jeremias Keihsler, 04.07.2020 15:18

1 1 Jeremias Keihsler
h1. Setup ssh-rsa-login
2
3
h2. Requirements
4
5
To install ssh you will need the following:
6 2 Jeremias Keihsler
* a installed and supported operating system (e.g. Fedora32)
7 1 Jeremias Keihsler
* root-access
8
* a fast internet connection
9
10
h2. Preliminary Note
11
12
You want to use Linux and OpenSSH to automize your tasks. Therefore you need an automatic login from host A / user a to Host B / user b. You don't want to enter any passwords, because you want to call ssh from a within a shell script.
13
This information was taken from 
14
* *Mathias Kettner* @ http://linuxproblem.org/art_9.html
15
* https://wiki.archlinux.org/index.php/SSH_keys#Choosing_the_authentication_key_type
16
17
h2. Setup 
18
19
First log in on A as user a and generate a pair of authentication keys. Do not enter a passphrase:
20
<pre><code class="bash">
21
a@A:~> ssh-keygen -t ed25519
22
Generating public/private rsa key pair.
23
Enter file in which to save the key (/home/a/.ssh/id_ed25519): 
24
Created directory '/home/a/.ssh'.
25
Enter passphrase (empty for no passphrase): 
26
Enter same passphrase again: 
27
Your identification has been saved in /home/a/.ssh/id_ed25519.
28
Your public key has been saved in /home/a/.ssh/id_ed25519.pub.
29
The key fingerprint is:
30
SHA256: CFyCCOw2e1Rz11avE7iU8GQy2Kb4tqqPHwztbPHlCqM a@A
31
</code></pre>
32
33
Now use ssh to create a directory ~/.ssh as user b on B. (The directory may already exist, which is fine):
34
35
<pre><code class="bash">
36
a@A:~> ssh b@B mkdir -p .ssh
37
b@B's password: 
38
</code></pre>
39
40
Finally append a's new public key to b@B:.ssh/authorized_keys and enter b's password one last time:
41
42
<pre><code class="bash">
43
a@A:~> cat .ssh/id_ed25519.pub | ssh b@B 'cat >> .ssh/authorized_keys'
44
b@B's password: 
45
</code></pre>
46
47
h2. Test 
48
49
From now on you can log into B as b from A as a without password:
50
51
<pre><code class="bash">
52
a@A:~> ssh b@B hostname
53
B
54
</code></pre>
55
56
h2. Troubleshooting 
57
58
If for any reason this is not working it might be because of wrong permissions or SELinux-context
59
60
<pre><code class="bash">
61
ll ~/.ssh
62
</code></pre>
63
needs permission-wise result in
64
<pre><code class="bash">
65
drwx------. 2 root root 4096 Aug  3 11:04 .
66
dr-xr-x---. 6 root root 4096 Aug  3 11:23 ..
67
-rw-r--r--. 1 root root  410 Aug  3 11:04 authorized_keys
68
-rw-------. 1 root root 1671 Aug  3 09:05 id_ed25519
69
-rw-r--r--. 1 root root  404 Aug  3 09:05 id_ed25519.pub
70
</code></pre>
71
to restore SELinux-context perform
72
<pre><code class="bash">
73
restorecon -R -v ~/.ssh
74
</code></pre>