SSH / sFTP return Connection refused


I change the permission with SSH (very simple just "chown -R ec2-user:apache /var/www/html/xxxxx/xxxx/xxx"), the SSH reject my connection and ssh: connect to host port 22: Connection refused... After that I check and reboot the EC2 but not effective...

What can I do...

asked 17 days ago21 views
1 Answer

In accordance with AWS, Apache httpd serves files that are kept in a directory called the Apache document root. The Amazon Linux Apache document root is /var/www/html, which by default is owned by root. (Your case may be /var/www/html/xxxx/public_html where you have made directory) To allow the ec2-user account to manipulate files in this directory, you must modify the ownership and permissions of the directory. There are a few ways to perform this task. AWS tutorial suggests, you add ec2-user to the apache group, to give apache group ownership of the /var/www directory and assign write permissions to the group.

Add your user (ec2-user) to the apachegroup

$sudo usermod -a -G apache ec2-user

Change the group ownership of /var/www and its contents to the apache group.

$sudo chown -R ec2-user:apache /var/www (Do not forget to add your directories, /var/www/html/xxxxx/xxxx/xxx)

If you are using the SSH client (Linux, Ubuntu) and downloed the file and copied in the Downloaded folder.

$chmod 400 x.pem (x.pem, replace with your pem file)

If your subnet is configured to get public IP automatically, then every reboot you get new IP address and as such your public dns changes.

If you are using EC2 Instance connect, please check your security group.

Please navigate this link:

Please let me know, I am also learning.

answered 17 days ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions