How to generate a private-public key using ssh-keygen and make it authorized?
I want to generate a public-private key on Sever 1 and store it in a location which is not the default location.
Thereafter, save the public key on Server 2; once again NOT at the default location.
Then make this key an authorized key.
However, I cannot find authorized_keys
file in ~/.ssh
folder. How do I make it authorized?
- Run
ssh-keygen -f filename
. - Run
scp filename username@server:filename-on-server
- Log in to the server and run
cat filename-on-server >> ~/.ssh/authorized_keys
You could also replace steps 2 and 3 with ssh-copy-id -i filename username@server
.
Use ssh-keygen
command. On the server (where you want ssh to) store the public key in file ~/.ssh/authorized_keys
. If you haven't got an .ssh directory inside your home (~) yet, create it (also be careful: it seems sshd is picky - for security reasons - that no other user can read that file/dir, it's better to issue chmod 700 on your .ssh directory and chmod 600 on the file in it).
On the machine you want to ssh from ("client"), you can use the private key to ssh to your server then. You can store it anywhere then you can use the -i
switch of ssh, to give the public key which will be used. I write this, since you stated that "not storing at the default location". The default location would be file id_dsa
(for DSA key) inside your .ssh directory. Then you don't need the -i
switch to specify your key, because it will be picked from there automatically.