I have setup a web server that hosts a Play! Framework application, the server is an Amazon Linux EC2.
If you are not familiar with Amazon Linux, by default there is a root user and an ec2-user with sudo privileges. To access the server you ssh in as the ec2-user using a key, passwords are disabled.
I want this application to be as secure as possible, and this setup seemed insecure to me; if someone is able to get the ssh key they will have root access to the machine.
To harden the server I added a new user "Play". I store and run the application from the Play users home folder. I then removed the sudo command from the ec2-user and added a password to root.
So now I login via ssh as the ec2-user who has no sudo privileges, then switch to the root/Play user to make any changes or do work on the server.
This seems like a fairly secure solution, however I would like to take it one step further: I want to limit the user I use to log in as (ec2-user) to only 1 command: "su - ". This is all I will be using this user for: switching to root.
For reference these are the commands I ran for this setup:
sudo su -
Added password to root:
Added Play user:
sudo adduser Play
Remove ec2-user from sudoers
cd /etc/sudoers.d nano cloud-init
Remove ec2-user and update file to:
Play ALL= NOPASSWD: ALL # User rules for ec2-user Play ALL=(ALL) NOPASSWD:ALL
thanks in advance for your help/advice!