Generate a keypair for server-side user accounts
#!/bin/bash -e
rlwrap ssh-keygen -t rsa -b 2048
id_ed25519
: Private keyid_ed25519.pub
: Public keyNow as a good practice rename keys according to server. For example :
smk.prvkey
and smk.pubkey
Never share your private key. Never ever never!
smk.pubkey
should be appended to "$HOME/.ssh/authorized_keys"
on the server. This is the key you should share if someone asks for ssh
keys.
Finally
service ssh restart
Next Step is setting up a config file locally so that we can access the server easily
touch ~/.ssh/config
Now open the file in favorite editor and write this block of lines for each server. (Notice the tab spacing!)
host *
Protocol 2
Compression no
StrictHostKeyChecking no
host smk
Hostname 195.223.83.209
port 22
User smk
IdentifyFile ~/.ssh/smk.prvkey
host smkbsd
Hostname 208.231.216.195
port 22
User smk
IdentifyFile ~/.ssh/smk.prvkey
So above config file gives us access to two servers which have our public key appended into authorized_keys file
A good practice is to limit the permission on files and directory .ssh
. This is from man page of ssh
~/.ssh/
: 700
, authorized_keys
: 600
, smk.pubkey
: 644
smk.prvkey
: 600
and config
: 600
to change permissions use chmod
for e. g. sudo chmod 700 ~/.ssh
or sudo chmod 600 ~/.ssh/config
Now to login into the server
ssh smk
or
ssh smkbsd