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?

  • 1
    ssh-keygen is the command for generating keys. It asks for location of key file during creation. I think you have to create the file authorised key if you don't have one Feb 14, 2011 at 11:02

3 Answers 3

  1. Run ssh-keygen -f filename.
  2. Run scp filename username@server:filename-on-server
  3. 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.

  • I get an error: too many arguments Oct 24, 2016 at 18:37
  • @Igor at which step?
    – Mikel
    Oct 25, 2016 at 3:01
  • 1
    Should you not append filename.pub rather than filename (which will be your private key?)
    – Samuel
    Mar 21, 2017 at 14:16

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.


Sounds like you've already made the keys. If not, just run ssh-keygen and accept the defaults. Make the authorized_keys file yourself: touch authorized_keys

When you keep your private keys in a non-standard location, make sure and use -i: ssh -i /path/to/privatekey user@host

Here's a good article on ssh-keygen and using authorized_keys to simplify ssh logins:


You must log in to answer this question.