---
title: "Discussion on \"Users and SSH setup on AWS EC2 - Best Practices\" | Hashnode"
description: "Discussion on \"Users and SSH setup on AWS EC2 - Best Practices\". I work with many startups and sometimes I want access to their EC2 instances on AWS. When I ask, often people send me a private key (a PEM file) to login! This distresses me to no end.\nGuys, didn't you know that a private key is, ahem, private?\nWhen ..."
url: "https://hashnode.com/posts/users-and-ssh-setup-on-aws-ec2-best-practices/594e7399dab431e2eda595dd"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Users and SSH setup on AWS EC2 - Best Practices](https://hashnode.com/post/users-and-ssh-setup-on-aws-ec2-best-practices?utm_source=hashnode&utm_medium=feed)

I work with many startups and sometimes I want access to their EC2 instances on AWS. When I ask, often people send me a private key (a PEM file) to login! This distresses me to no end. Guys, didn't you know that a private key is, ahem, private? When ...

Jun 24, 2017 · hashnode.com  
Updated Jun 27, 2017  
Read the article

-   [#security](https://hashnode.com/tag/security)
-   [#aws](https://hashnode.com/tag/aws)
-   [#best-practices](https://hashnode.com/tag/best-practices)
-   [#devops](https://hashnode.com/tag/devops)
-   [#ssh](https://hashnode.com/tag/ssh)

## Written by

[Vasan Subramanian](https://hashnode.com/@vasan)

@vasan · Bangalore

  
[View profile](https://hashnode.com/@vasan)

Previous generation techie

I work with startups, specialize in web technologies, agile processes and devops. I also dabble around with Android programming.

## Responses 8

Markdown supported · ⌘↵ to post

[Juvanta Luiz](https://hashnode.com/@Juvanta)

[Apr 9, 2022](https://hashnode.com/posts/users-and-ssh-setup-on-aws-ec2-best-practices/594e7399dab431e2eda595dd/comment/6251b1b392d73e7055c1850c)

I have tried out the code that you have provided to Users and SSH setup on AWS EC2 and the explanation you have added really helped me a lot to understand the code [mobile shop in oman](https://www.sarcoonline.com/Smart-Phones-Oman) that you have shared here

[Jack Marrow](https://hashnode.com/@jackmarrow)

[Apr 23, 2021](https://hashnode.com/posts/users-and-ssh-setup-on-aws-ec2-best-practices/594e7399dab431e2eda595dd/comment/60823138ff5fc65284a7719b)

In a terminal window, use the ssh command to connect to the instance. You specify the path and file name of the private key ( . pem ), the user name for your instance, and the public DNS name or IPv6 address for your instance. - aws.amazon ( [electricians near me](https://www.electriciannorthshoreauckland.info/) )

[Macario James](https://hashnode.com/@Macariojames)

[Jan 25, 2019](https://hashnode.com/posts/users-and-ssh-setup-on-aws-ec2-best-practices/594e7399dab431e2eda595dd/comment/5c4a649cc7a6bc465da5cb8e)

Opened my eyes to several practices I am going to implement ASAP into my organization's policies. Thank you.

[Addeline joseph](https://hashnode.com/@addeline)

[Sep 12, 2017](https://hashnode.com/posts/users-and-ssh-setup-on-aws-ec2-best-practices/594e7399dab431e2eda595dd/comment/59b7d169792fd39a38c12482)

I work with many startups and sometimes I want access to their **EC2** instances **on** AWS. When I ask, often people send me a private key (a PEM file) to login! . The best part about besant technologies is that even after completion of course they provide free technical support and they will be sending you JOB Opening Mails. [trainingbangalore.in/amazon-web-services-training…](http://www.trainingbangalore.in/amazon-web-services-training-in-bangalore.html)

[Siddarthan Sarumathi Pandian](https://hashnode.com/@spsiddarthan)

[Jun 30, 2017](https://hashnode.com/posts/users-and-ssh-setup-on-aws-ec2-best-practices/594e7399dab431e2eda595dd/comment/5955fedb6c7495b778015949)

Totally waiting for another piece on IAM user role management. :D

[Sébastien Portebois](https://hashnode.com/@sportebois)

[Jul 2, 2017](https://hashnode.com/posts/users-and-ssh-setup-on-aws-ec2-best-practices/594e7399dab431e2eda595dd/comment/5955fedb6c7495b778015949#reply-59593a1223c1a21334cffccc)

In fact, you can already use IAM and let user manage their CodeCommit SSH key... but use that ssh-key for other purposes. I use that to make it easier : user manage their own ssh key, but the instances use iam groups to sync user with some users, and when a ssh connection needs to be established the key is read from IAM

The simple demos are available there: (for production use, you'd want to populate theses scripts from your cloudinit script, and restrict the user sync to only a specific group)

[github.com/sportebois/aws-ec2-ssh-sync](https://github.com/sportebois/aws-ec2-ssh-sync)

HTH

[Siddarthan Sarumathi Pandian](https://hashnode.com/@spsiddarthan)

[Jul 3, 2017](https://hashnode.com/posts/users-and-ssh-setup-on-aws-ec2-best-practices/594e7399dab431e2eda595dd/comment/5955fedb6c7495b778015949#reply-5959dc590b9aca6c0b3e23c4)

Thank you :D

[Anuj Sharma](https://hashnode.com/@anujnode)

[Jun 26, 2017](https://hashnode.com/posts/users-and-ssh-setup-on-aws-ec2-best-practices/594e7399dab431e2eda595dd/comment/59509401407ec717aa306829)

[Vasan Subramanian](https://hashnode.com/@vasan "Vasan Subramanian's Profile - Hashnode") Thanks for sharing your experience. It's "Make My Day moment".

[Mahesh Vaidya](https://hashnode.com/@forvaidya)

[Jun 24, 2017](https://hashnode.com/posts/users-and-ssh-setup-on-aws-ec2-best-practices/594e7399dab431e2eda595dd/comment/594ea4e107008bbf7ffdd4a5)

A weakness of SSH is SSH private key never expire. We can use AuthorizedKeysCommand

We can also alter ~/.authorized\_keys content based on some key store. In AMI we need to configure AuthorizedKeysCommand which will run every time before public key is compared in ~/.authorized\_keys and recreate ~/.authorized\_keys based on user uploaded keys or admin deleted keys.

this github project have implementation [github.com/widdix/aws-ec2-ssh](https://github.com/widdix/aws-ec2-ssh)
