Couldn’t setup sftp in ec2

amazon ec2sftpvsftpd

I was trying to setup sftp in AWS EC2 by following the instructions in https://silicondales.com/tutorials/aws-ec2-tutorials/setup-ftp-sftp-aws-ec2-instance/

I have done below steps

  1. Launched a new EC2 instance
  2. Logged in as ec2-user
  3. Installed vsftpd
  4. Updated security group rules by Custom TCP Rules – port ranges 20-21 and 1024-1048
  5. Below changes are done in /etc/vsftpd/vsftpd.conf

    anonymous_enable=NO
    pasv_enable=YES
    pasv_min_port=1024
    pasv_max_port=1048
    pasv_address=[MY PUBLIC IP]
    chroot_local_user=YES
    
  6. Created a new user and set the password

    adduser silicondales
    passwd silicondales
    
  7. Restarted /etc/init.d/vsftpd restart. It is successful as I get the message

After all this I try to connect from my local machine

sftp -oPort=1024 <username>:<password>@<public ip address> and getting ssh: connect to host <Public_IP> port 1024: Connection refused error.I couldn't figure out the issue. Please help me to solve this

Best Answer

SSH, which is already running, provides SFTP. The same key you login to SSH with allows SFTP logins. The SFTP service is provided by SSH, the same software that lets you log in.

You can add users and allow them to login via SFTP. This for example makes it easier to create a user that only has access to your webroot. I have an article about that for Amazon Linux on my blog, which includes some pictures. The essential parts are

Create a new user

sudo su
sudo useradd fred
passwd fred

Create a new key pair

su fred
ssh-keygen -f rsa

mkdir .ssh

touch .ssh/authorized_keys
chmod go-w ~/
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

cat fred.pub >> /home/fred/.ssh/authorized_keys

Allow the user to log in

vi /etc/ssh/sshd_config
PasswordAuthentication no
AllowUsers ec2-user fred
Related Topic