Projekt

Allgemein

Profil

Setup ssh-rsalogin » Historie » Version 1

Jeremias Keihsler, 10.09.2020 14:34

1 1 Jeremias Keihsler
h1. Setup ssh-rsa-login
2
3
h2. Requirements
4
5
To install ssh you will need the following:
6
* a installed and supported operating system (e.g. CentOS 8.x)
7
* 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 *Mathias Kettner* @ http://linuxproblem.org/art_9.html
14
15
h2. Setup 
16
17
First log in on A as user a and generate a pair of authentication keys. Do not enter a passphrase:
18
<pre><code class="bash">
19
a@A:~> ssh-keygen -t rsa
20
Generating public/private rsa key pair.
21
Enter file in which to save the key (/home/a/.ssh/id_rsa): 
22
Created directory '/home/a/.ssh'.
23
Enter passphrase (empty for no passphrase): 
24
Enter same passphrase again: 
25
Your identification has been saved in /home/a/.ssh/id_rsa.
26
Your public key has been saved in /home/a/.ssh/id_rsa.pub.
27
The key fingerprint is:
28
3e:4f:05:79:3a:9f:96:7c:3b:ad:e9:58:37:bc:37:e4 a@A
29
</code></pre>
30
31
Now use ssh to create a directory ~/.ssh as user b on B. (The directory may already exist, which is fine):
32
33
<pre><code class="bash">
34
a@A:~> ssh b@B mkdir -p .ssh
35
b@B's password: 
36
</code></pre>
37
38
Finally append a's new public key to b@B:.ssh/authorized_keys and enter b's password one last time:
39
40
<pre><code class="bash">
41
a@A:~> cat .ssh/id_rsa.pub | ssh b@B 'cat >> .ssh/authorized_keys'
42
b@B's password: 
43
</code></pre>
44
45
h2. Test 
46
47
From now on you can log into B as b from A as a without password:
48
49
<pre><code class="bash">
50
a@A:~> ssh b@B hostname
51
B
52
</code></pre>
53
54
h2. Troubleshooting 
55
56
If for any reason this is not working it might be because of wrong permissions or SELinux-context
57
58
<pre><code class="bash">
59
chmod 700 ~/.ssh
60
ll ~/.ssh
61
</code></pre>
62
needs permission-wise result in
63
<pre><code class="bash">
64
drwx------. 2 root root 4096 Aug  3 11:04 .
65
dr-xr-x---. 6 root root 4096 Aug  3 11:23 ..
66
-rw-r--r--. 1 root root  410 Aug  3 11:04 authorized_keys
67
-rw-------. 1 root root 1671 Aug  3 09:05 id_rsa
68
-rw-r--r--. 1 root root  404 Aug  3 09:05 id_rsa.pub
69
</code></pre>
70
to restore SELinux-context perform
71
<pre><code class="bash">
72
restorecon -R -v ~/.ssh
73
</code></pre>