Setup ssh-rsalogin » Historie » Revision 1
Revision 1/5
| Weiter »
Jeremias Keihsler, 10.09.2020 14:34
Setup ssh-rsa-login¶
Requirements¶
To install ssh you will need the following:- a installed and supported operating system (e.g. CentOS 8.x)
- root-access
- a fast internet connection
Preliminary Note¶
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.
This information was taken from Mathias Kettner @ http://linuxproblem.org/art_9.html
Setup¶
First log in on A as user a and generate a pair of authentication keys. Do not enter a passphrase:
a@A:~> ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/a/.ssh/id_rsa):
Created directory '/home/a/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/a/.ssh/id_rsa.
Your public key has been saved in /home/a/.ssh/id_rsa.pub.
The key fingerprint is:
3e:4f:05:79:3a:9f:96:7c:3b:ad:e9:58:37:bc:37:e4 a@A
Now use ssh to create a directory ~/.ssh as user b on B. (The directory may already exist, which is fine):
a@A:~> ssh b@B mkdir -p .ssh
b@B's password:
Finally append a's new public key to b@B:.ssh/authorized_keys and enter b's password one last time:
a@A:~> cat .ssh/id_rsa.pub | ssh b@B 'cat >> .ssh/authorized_keys'
b@B's password:
Test¶
From now on you can log into B as b from A as a without password:
a@A:~> ssh b@B hostname
B
Troubleshooting¶
If for any reason this is not working it might be because of wrong permissions or SELinux-context
chmod 700 ~/.ssh
ll ~/.ssh
needs permission-wise result in
drwx------. 2 root root 4096 Aug 3 11:04 .
dr-xr-x---. 6 root root 4096 Aug 3 11:23 ..
-rw-r--r--. 1 root root 410 Aug 3 11:04 authorized_keys
-rw-------. 1 root root 1671 Aug 3 09:05 id_rsa
-rw-r--r--. 1 root root 404 Aug 3 09:05 id_rsa.pub
to restore SELinux-context perform
restorecon -R -v ~/.ssh
Von Jeremias Keihsler vor mehr als 4 Jahren aktualisiert · 1 Revisionen