Create your own .pem for ssh login using certificate

Some of my colleagues asking me this, how can i login to my server using certificate like i login to aws (amazon web services).

1. Setup your server


awan@google.com# ssh-keygen -t rsa -b 2048
awan@google.com# cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

2. Copy your secrets to your a file let’s give it a name ‘awan.access.pem’, you can give it any name you want


awan@local_machine.dev.google.com# scp awan@google.com:~/.ssh/id_rsa .
awan@local_machine.dev.google.com# cp id_rsa awan.access.pem
awan@local_machine.dev.google.com# chmod 0600 awan.access.pem

or just cat the id_rsa file, copy the content to a file and rename the file

3. Let’s access our box using .pem certificate file from any box, please don’t share the key to unauthorized personel


awan@local_machine.dev.google.com# ssh -i awan.access.pem awan@google.com

awan : change is to your username
google.com : this is also an example, change this to your server ip, linux box, or your domain name

after step number 2 your can create image or snapshot from the virtual machine or container so next time you login you don’t have to regenerate the key anymore.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s