- Navigate to Services | Compute | EC2
- Pick a region from upper right drop down
- Remember: EC2 is a per region service. Instances will be deployed in the region selected.
- Choose Launch Instance and then optionally select Free tier only checkbox.
- Chose Amazon Linux 2 AMI (HVM), SSD Volume Type.
- Chose t2.micro instance and then Next: Configure Instance Details
- Keep all the options default assuming Number of Instances is 1 and chose Next: Add Storage
- Keep default 8 GB General Purpose SSD (gp2) and chose Next: Add Tags
- Remember: 12 month free tier provides 30 GB of EBS storage, combined over any combination of General Purpose (SSD) or Magnetic Disks
- Add tags as desired and chose Next: Configure Security Group
- Tags are key value pairs you define to assist with management as your AWS environment grows.
- A simple but useful tag example might be Name : OpenSSHserver01
- Chose Create a new security group, name it WebDMZ or something appropriate. The idea is we are controlling access to this server from the Internet. Chose Review and Launch
- One rule needs to be SSH over TCP port 22 from Anywhere, or optionally a specific IP if possible.
- Review options and choose Launch
- When prompted, chose an existing keypair or create a new one. If creating new, download the keypair to a known location. Chose Launch Instances.
- Chose View Instances and monitor progress.
- When the Instance State changes to running you can test remote access.
- In the AWS Console, copy the IPv4 Public Address to your clipboard.
- If you created a new keypair, in Windows run PuTTYgen.
- Choose Load and point to your .pem file you downloaded previously. You may have to change the file type to All Files *.* to find it. Then choose Save private key to use it in PuTTY. Name and save it somewhere appropriate.
- Open PuTTY, expand SSH and chose Auth.
- Browse to the new private key you just saved.
- Choose Session, paste the IPv4 Public Address into Host Name (or IP Address)
- When prompted for a user name, enter ec2-user
- It would be a good idea to run sudo yum update to apply any available updates.
Change server remote access from keypair to user / password authentication:
- Set a password for ec2-user via sudo passwd ec2-user
- Open sshd_config file via sudo nano ../../etc/ssh/sshd_config
- Change PasswordAuthentication no to PasswordAuthentication yes
- Restart the SSH service via sudo service sshd restart
- Test access via SFTP using username / password authentication (I personally use the WinSCP client)
- Test CRUD access by copying and deleting file in /home/ec2-user folder
Create a CHROOT jail for SFTP user(s):
- Create a new user group via sudo groupadd sftponly where sftponly is your group name
- Add a new user and prevent SSH login via /bin/false via sudo useradd -g sftponly -s /bin/false -m -d /home/sftpuser sftpuser where sftpuser is the username
- IF the user already exists, modify it appropriately via sudo usermod -G sftponly -s /bin/false sftpuser
- Set the new user password via sudo passwd sftpuser
- Change the permissions on the user's home directory. Make root the owner, essentially disabling access from the new user. Run:
- sudo chown root /home/sftpuser
- sudo chmod 755 /home/sftpuser
- Create a home sub-directory that the new user can use, here sftpfolder. Run:
- sudo mkdir /home/sftpuser/sftpfolder
- sudo chmod 755 /home/sftpuser/sftpfolder
- sudo chown sftpuser:sftponly /home/sftpuser/sftpfolder
- Configure SSH via sudo nano ../../etc/ssh/sshd_config
- Change the sftp subsystem. Change subsystem sftp /usr/lib/openssh/sftp-server line to subsystem sftp internal-sftp
- Add information re: the sftponly group to the SSH configuration. Add the following to the end of the sshd_config file:
- Match Group sftponly
- ChrootDirectory %h
- ForceCommand internal-sftp
- AllowTcpForwarding no
- X11Forwarding no
- restart SSH via service sshd restart
No comments:
Post a Comment