DEV Community

Cover image for Generate SSH key
Vadim Filimonov
Vadim Filimonov

Posted on

Generate SSH key

You need ssh key to connect to the server without a password.

I. Create a new ssh key

Enter the command:

ssh-keygen -t rsa -b 4096 -C "login@mail.com"
Enter fullscreen mode Exit fullscreen mode

The terminal asks you to set a password for the key and specify the location where it will be located. If you don't need it just press enter to the end.

The file will be located at:

/home/user/.ssh/id_rsa.pub
Enter fullscreen mode Exit fullscreen mode

The contents of this file are your public key.

II. Add ssh key to the server

Enter the command:

ssh-copy-id user@server.com
Enter fullscreen mode Exit fullscreen mode

Enter the password.
PROFIT.

Discussion (2)

Collapse
ferricoxide profile image
Thomas H Jones II

It would be a really bad idea to not password-protect your key (especially if you're logging in to an account that has sudoers capabilities).

Collapse
vadimfilimonov profile image
Vadim Filimonov Author

I agree but it is a case study. I tried to write it shortly.