<p>Although i have not found out what leads to this. But i am finally able to login into my instance by following these steps:
1. As you are logged in create a user in the instance and give it a password.</p>

<pre><code>$ adduser user1
$ passwd user1
</code></pre>

<p>2. Enable password authentication in /etc/sshd_config file.
3. Login with the new user.</p>

<p>Interestingly, this user does not gets locked out as the centos user.</p>

CC BY-SA 3.0
2017-07-28T06:22:39.313Z
2017-07-28T06:22:39.313Z
lakshayk
<p>One way I get locked out while developing is by changing the permissions on any of the directories or files associated with the keys used by <code>ssh</code>.  This happens to me when I untar files or run some installation script while initializing the machine that touches the <code>ec2-user</code> account.</p>

<p>Make sure the permissions are like:</p>

<pre><code>1&gt; ls -ld $HOME $HOME/.ssh
drwx------ 15 ec2-user ec2-user 4096 Aug  1 13:15 /home/ec2-user/
drwx------  2 ec2-user ec2-user 4096 Jun 10 11:18 /home/ec2-user/.ssh/

2&gt; ls -l $HOME/.ssh/authorized_keys
-rw------- 1 ec2-user ec2-user 385 Jun 10 11:18 /home/ec2-user/.ssh/authorized_keys
</code></pre>

<p>If not, and you are logged in as <code>ec2-user</code>, you can change them with </p>

<pre><code>sudo chown ec2-user:ec2-user ~ec2-user ~ec2-user/.ssh ~ec2-user/.ssh/authorized_keys
chmod 700 ~ec2-user ~ec2-user/.ssh
chmod 600 ~ec2-user/.ssh/authorized_keys
</code></pre>

<p>To protect myself against my own mistakes, I create a new user and copy the <code>ec2-user</code> key over.  That account is used as a backup and not part of any script.  Once I tested everything, I remove the account.</p>

CC BY-SA 3.0
2017-08-09T11:27:15.030Z
2017-08-11T15:21:40.847Z
2017-08-11T15:21:40.847Z
Hbar
<p><strong>Thumb Rule:</strong> Not finding a root cause is Not a solution</p>

<p>Now from your inputs What we get is </p>

<ol>
<li>You get locked out while using SSH login (passwordless)</li>
<li>You are able to login if its password login</li>
</ol>

<p>what I think might have happened is that your private key file format might have been changing (one consideration is EOL) if you are using a windows / mac or linux editors or switching between them for SSHing into the remote.</p>

<p>So do a "cat -e ~/.ssh/id_rsa" and check the contents if you see a ^M at the End of the line , then most probably you have edited the private file with a CRLF editor. Do a "dos2unix ~/.ssh/id_rsa" to convert the file to LF format</p>

<p>Check this
<a href="https://unix.stackexchange.com/questions/32001/what-is-m-and-how-do-i-get-rid-of-it">https://unix.stackexchange.com/questions/32001/what-is-m-and-how-do-i-get-rid-of-it</a></p>

CC BY-SA 3.0
2017-08-12T03:31:50.720Z
2017-08-12T03:31:50.720Z
Ameen Ibrahim Raffic - 'AIR'
<p>I am getting continously locked out from my ec2 instance time and again. I have to take its root volume and attach it to some other instance (mostly new instance) to prevent data loss. I am not able to figure out what is causing my ssh being denied. It works for sometime and all of a sudden ssh is denied. I have tried</p>

<ol>
<li>Comparing the authkeys with my login key. It is same.</li>
<li>Copying the key from a ssh working instance to this volume and re-launching. Same error.</li>
<li>Did some tweaks in sshd_conf and ssh_conf but to no success.</li>
</ol>

<p>I am completely stumped here, any viewpoints on this.
I have been working on AWS for sometime now and never encountered this problem, the only change being the organsation (and the network) has changed from where i am working from? Can their network be generated some kind of DOS attack which is just shutting down my ssh access? 
My team does not have an official AWS tech support plan, hence here.</p>

CC BY-SA 3.0
2017-07-26T15:48:32.353Z
Is it possible your machines are getting compromised?
Xiong Chiamiov
CC BY-SA 3.0
2017-07-26T16:10:36.527Z
Are these Red Hat AMIs? I've been experiencing a similar issue on new deployments for Red Hat on physical iron and other VMWare infrastructure.
James Shewey
CC BY-SA 3.0
2017-07-27T03:15:34.370Z
@XiongChiamiov, i'll look into this today.
lakshayk
CC BY-SA 3.0
2017-07-27T03:15:58.937Z
@JamesShewey, no they are CentOS 7 AMIs
lakshayk
<amazon-web-services><amazon-ec2>
Continuously getting locked out from EC2 instance. No supported authentication methods available
lakshayk
# Continuously getting locked out from EC2 instance. No supported authentication methods available

(Asked by: username_0 on 2017-07-26)

I am getting continously locked out from my ec2 instance time and again. I have to take its root volume and attach it to some other instance (mostly new instance) to prevent data loss. I am not able to figure out what is causing my ssh being denied. It works for sometime and all of a sudden ssh is denied. I have tried

1. Comparing the authkeys with my login key. It is same.
2. Copying the key from a ssh working instance to this volume and re-launching. Same error.
3. Did some tweaks in sshd\_conf and ssh\_conf but to no success.

I am completely stumped here, any viewpoints on this.
I have been working on AWS for sometime now and never encountered this problem, the only change being the organsation (and the network) has changed from where i am working from? Can their network be generated some kind of DOS attack which is just shutting down my ssh access?
My team does not have an official AWS tech support plan, hence here.

**Tags:** amazon-web-services, amazon-ec2

> **Comments:**
> **username_1**: Is it possible your machines are getting compromised?  
> **username_2**: Are these Red Hat AMIs? I've been experiencing a similar issue on new deployments for Red Hat on physical iron and other VMWare infrastructure.  
> **username_0**: @XiongChiamiov, i'll look into this today.  
> **username_0**: @JamesShewey, no they are CentOS 7 AMIs  

---

## 3 answers

### Answer by username_0 on 2017-07-28. Score: 3 | Accepted answer

Although i have not found out what leads to this. But i am finally able to login into my instance by following these steps:
1. As you are logged in create a user in the instance and give it a password.
$ adduser user1
$ passwd user1

2. Enable password authentication in /etc/sshd_config file.
3. Login with the new user.
Interestingly, this user does not gets locked out as the centos user.


---

### Answer by username_3 on 2017-08-09. Score: 2

One way I get locked out while developing is by changing the permissions on any of the directories or files associated with the keys used by ssh.  This happens to me when I untar files or run some installation script while initializing the machine that touches the ec2-user account.
Make sure the permissions are like:
1> ls -ld $HOME $HOME/.ssh
drwx------ 15 ec2-user ec2-user 4096 Aug  1 13:15 /home/ec2-user/
drwx------  2 ec2-user ec2-user 4096 Jun 10 11:18 /home/ec2-user/.ssh/

2> ls -l $HOME/.ssh/authorized_keys
-rw------- 1 ec2-user ec2-user 385 Jun 10 11:18 /home/ec2-user/.ssh/authorized_keys

If not, and you are logged in as ec2-user, you can change them with 
sudo chown ec2-user:ec2-user ~ec2-user ~ec2-user/.ssh ~ec2-user/.ssh/authorized_keys
chmod 700 ~ec2-user ~ec2-user/.ssh
chmod 600 ~ec2-user/.ssh/authorized_keys

To protect myself against my own mistakes, I create a new user and copy the ec2-user key over.  That account is used as a backup and not part of any script.  Once I tested everything, I remove the account.


---

### Answer by username_4 on 2017-08-12. Score: 0

**Thumb Rule:** Not finding a root cause is Not a solution

Now from your inputs What we get is

1. You get locked out while using SSH login (passwordless)
2. You are able to login if its password login

what I think might have happened is that your private key file format might have been changing (one consideration is EOL) if you are using a windows / mac or linux editors or switching between them for SSHing into the remote.

So do a "cat -e ~/.ssh/id\_rsa" and check the contents if you see a ^M at the End of the line , then most probably you have edited the private file with a CRLF editor. Do a "dos2unix ~/.ssh/id\_rsa" to convert the file to LF format

Check this
<https://unix.stackexchange.com/questions/32001/what-is-m-and-how-do-i-get-rid-of-it>


---

