1

I accidentally added my root user to my sftp group using command:

sudo usermod -a -G sftp ubuntu

And now everytime I tried to login my linux server it shows this error: enter image description here

I do not have any other users in the server. How do I fix it?

roaima
  • 107,089
  • 14
  • 139
  • 261
user535660
  • 11
  • 1

2 Answers2

2

Since you are working with an AWS EC2 instance, you really only have one option for recovery: stopping the instance, mounting the EBS volume to another EC2 instance, and then manually modifying the /etc/group file to remove the ubuntu user from the sftp group.

AWS provides instructions on how to mount the EBS volume onto another EC2 instance at this documentation link. In the interests of fighting link-rot the steps are:

To attach an EBS volume to an instance using the console

  1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/

  2. In the navigation pane, choose Volumes.

  3. Select the volume to attach and choose Actions, Attach volume.

Note

You can attach only volumes that are in the Available state.

  1. For Instance, enter the ID of the instance or select the instance from the list of options.

Note

The volume must be attached to an instance in the same Availability Zone.

If the volume is encrypted, it can only be attached to instance types that support Amazon EBS encryption. For more information, see Amazon EBS encryption.

  1. For Device name, enter a supported device name for the volume. This device name is used by Amazon EC2. The block device driver for the instance might assign a different device name when mounting the volume. For more information, see Device names on Linux instances.

  2. Choose Attach volume.

  3. Connect to the instance and mount the volume. For more information, see Make an Amazon EBS volume available for use on Linux.

After you have removed the ubuntu user from the sftp group, you can disconnect the volume from the EC2 instance you were working on, start up the original EC2 instance that had the error, and SSH to it normally.

Thegs
  • 673
  • 3
  • 9
  • Out of interest how do you know this is AWS? – roaima Jul 29 '22 at 23:40
  • 1
    @roaima Running `whois` for the IP address displayed in the picture as the SSH connection target will indicate it is operated by "Amazon AWS Network Operations". Also, anyone that's been using AWS themselves a lot might recognize the IP address range on sight. – telcoM Jul 30 '22 at 03:58
  • 1
    @roaima telecoM has it right in the second part, I was briefly a CSE for AWS so I got pretty familiar with their most popular IP spaces. What hinted at me was the username was `ubuntu`, that's a very AWS thing, and I've only seen it also in the Ubuntu installation disc. – Thegs Jul 30 '22 at 13:20
0

Don't login as root. Login as your administrative user and use sudo -s to get a root shell.

Failing that, boot a rescue image and use that to reset root's groups membership

roaima
  • 107,089
  • 14
  • 139
  • 261