mag37 / ssh_key-setup.md

Last active 1 month ago

Like 0

mag37 revised this gist 1 month ago · 391e725

1 file changed, 2 insertions, 2 deletions

ssh_key-setup.md
@@ -1,4 +1,4 @@
1 - # Setting up a keypair and adding it to remote server:
1 + ## Setting up a keypair and adding it to remote server:
2 2
3 3 Generate keypair (will be asked where to save if no -f, default is fine):
4 4 ```sh
@@ -28,7 +28,7 @@ ssh -vvv -i ~/.ssh/filename.pub USER@REMOTEHOST
28 28 sudo journalctl -t sshd -n 100
29 29 ```
30 30
31 - # Setting up a ssh-config for multiple keys / servers
31 + ## Setting up a ssh-config for multiple keys / servers
32 32
33 33 In `~/.ssh/config` add something like:
34 34 ```ini

mag37 revised this gist 1 month ago · 2dd4fc4

1 file changed, 53 insertions

ssh_key-setup.md (file created)
@@ -0,0 +1,53 @@
1 + # Setting up a keypair and adding it to remote server:
2 +
3 + Generate keypair (will be asked where to save if no -f, default is fine):
4 + ```sh
5 + ssh-keygen -t ed25519 -f ~/.ssh/filename -C "<comment/email>"
6 + ```
7 +
8 + Copy public key to remote server:
9 + ```sh
10 + # with ssh-copy-id tool:
11 + ssh-copy-id -i ~/.ssh/filename.pub USER@REMOTEHOST
12 +
13 + # manually, permissions are required!
14 + cat ~/.ssh/filename.pub | ssh USER@REMOTEHOST "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"
15 + ```
16 +
17 + Change passphrase of a file:
18 + ```sh
19 + ssh-keygen -p -f ~/.ssh/filename
20 + ```
21 +
22 + Troubleshoot:
23 + ```sh
24 + # on the client:
25 + ssh -vvv -i ~/.ssh/filename.pub USER@REMOTEHOST
26 +
27 + # on the remote:
28 + sudo journalctl -t sshd -n 100
29 + ```
30 +
31 + # Setting up a ssh-config for multiple keys / servers
32 +
33 + In `~/.ssh/config` add something like:
34 + ```ini
35 + Host tankbox
36 + HostName 10.0.0.9
37 + User storage
38 + IdentityFile ~/.ssh/tankbox
39 + Port 2323
40 +
41 + Host hypebox
42 + HostName 10.0.0.8
43 + User controller
44 + IdentityFile ~/.ssh/hypebox
45 + Port 22
46 + ```
47 + And now instead of specifying key+user+port every time, you'd just:
48 + ```sh
49 + ssh tankbox
50 + # or
51 + ssh hypebox
52 + ```
53 +