Last active
December 18, 2019 09:27
-
-
Save aonurdemir/43d8bb3f5d7dcfece4427e4c3838ab77 to your computer and use it in GitHub Desktop.
Add new pem file to EC2 - ssh - key - generate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Connect to machine you want to give access | |
$ sudo adduser <onur.demir> | |
$ sudo su <onur.demir> | |
make sure your are in user's home directory. | |
$ cd | |
Create .ssh directory, and change the directory permission to 700 (only the file owner can read, write or open the directory): | |
$ mkdir .ssh | |
$ chmod 700 .ssh | |
Create an empty file called authorized_keys in the .ssh directory and change its permissions to 600 (only the file owner can read or write to the file) | |
$ touch authorized_keys | |
$ chmod 600 authorized_keys | |
Go to AWS EC2 console. In the left navigation pane, select "Key Pairs". Then click "Create Key Pair". | |
Download private pem file. | |
Run below command in any linux or mac machine in order to get the public key of the private key: | |
ssh-keygen -y -f <pem-file> | |
Again in the machine you want to give access, open .ssh/authorized_key and append the public key just below the existing one(no empty line). | |
Add the name of the private key also like below: | |
ssh-rsa dfasgwfsdfefwefsdadqwDAQABAAABAQCl6BhEWO0Mzm2dasgtwfdsfwdqdq keyname | |
than connect to EC2 with your new user like: | |
$ ssh -i <pem-file> <new-username>@<ip> | |
your done :) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment