Skip to content

Instantly share code, notes, and snippets.

@tracend
Created November 5, 2012 12:02
Show Gist options
  • Save tracend/4016872 to your computer and use it in GitHub Desktop.
Save tracend/4016872 to your computer and use it in GitHub Desktop.
AWS EC2: Steps to enable root access with your local key - Inspired by: https://forums.aws.amazon.com/thread.jspa?threadID=86876

Note: replace {{server}} with your domain or ip

  • Login as the ec2-user
ssh -i key.pem ec2-user@{{server}}
  • Switch to administrator
sudo -i
  • Load the configuration file
sudo vi /etc/ssh/sshd_config
  • Make sure these are enabled:
	PermitRootLogin yes
	# Only allow root to run commands over ssh, no shell
	#PermitRootLogin forced-commands-only
	RSAAuthentication yes
	PubkeyAuthentication yes
	AuthorizedKeysFile     .ssh/authorized_keys
  • copy your local public key to the authorized list
cat ~/.ssh/id_rsa.pub | ssh root@{{server}} 'cat - >> ~/.ssh/authorized_keys'
  • Make sure the files have the right permisions
chmod 600 ~/.ssh/authorized_keys && chmod 700 ~/.ssh/
  • Restart the service
sudo service sshd reload
  • Exit and try to login again
exit
ssh root@{{server}}
@mohataher
Copy link

At this line, copy your local public key to the authorized list, on which machine should I execute this command?

@duy13
Copy link

duy13 commented Dec 3, 2016

Hi! this is tutorial version 2016:
How to login Root SSH Linux Server Amazon VPS (Amazon Web Services EC2) Elastic Compute Cloud
https://www.youtube.com/watch?v=KoKhLbkCX5g&index=4&list=PLbAauqV4HwDTc8OA58KjzbWFECap-E0u_

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment