Magento2.4.6 sftp cannot access /var/www/html, how to modify the permissions of html files

0

Hi, I installed magento2.4.6 on Ubuntu22.04. I don't know much about folder permissions, and now I can't login to /var/www/html files using sftp. How can I solve this problem?

【FileZilla】

Status:	Listing directory /var/www
Status:	Directory listing of "/var/www" successful
Status:	Retrieving directory listing of "/var/www/html"...
Command:	cd "html"
Error:	Directory /var/www/html: permission denied
Error:	Failed to retrieve directory listing

Enter image description here

【SSH】

root@ip-123-45-6-78:/var/www# ls -al
total 12
drwxr-xr-x  3 root     root     4096 Apr 21 07:34 .
drwxr-xr-x 14 root     root     4096 Apr 21 07:34 ..
drwx--x--x 12 www-data www-data 4096 Apr 21 14:23 html
root@ip-123-45-6-78/var/www#

Enter image description here

Angelo
asked a year ago395 views
4 Answers
1
Accepted Answer

Looking at the permissions below, it appears that users other than "www-data" do not have read/write permissions.

drwx--x--x 12 www-data www-data 4096 Apr 21 14:23 html

So try the following command.

chmod 775 -R /var/www/html
profile picture
EXPERT
answered a year ago
  • The default user is Ubuntu, and the permissions cannot be modified. After I switch to the root user, I can modify the permissions.

    Now I can open the html folder.

  • But I can't make any modifications to the file.

  • Make the Ubuntu user belong to the "www-data" group with the following command. The following commands must be executed as root user.

    usermod -aG www-data ubuntu
    
  • Thank you so much. I am now an ubuntu user, and I can upload files normally using FileZilla.

0

The default user is Ubuntu, and the permissions cannot be modified. After I switch to the root user, I can modify the permissions.

Now I can open the html folder.

But I can't make any modifications to the file.

Status:	Connected to 12.345.67.89
Status:	Retrieving directory listing of "/var/www"...
Status:	Listing directory /var/www
Status:	Directory listing of "/var/www" successful
Status:	Retrieving directory listing of "/var/www/html"...
Status:	Listing directory /var/www/html
Status:	Directory listing of "/var/www/html" successful
Status:	Starting upload of F:\Magento\theme\themeforest-TlWf1t1h-minimogmgt-the-high-converting-magento-2-theme\Minimog_Package_1.1.9\Base_Start_Package\minimog_theme\minimog_theme.zip
Status:	Retrieving directory listing of "/var/www/html"...
Status:	Listing directory /var/www/html
Command:	put "F:\Magento\theme\themeforest-TlWf1t1h-minimogmgt-the-high-converting-magento-2-theme\Minimog_Package_1.1.9\Base_Start_Package\minimog_theme\minimog_theme.zip" "minimog_theme.zip"
Error:	/var/www/html/minimog_theme.zip: open for write: permission denied
Error:	File transfer failed
Status:	Retrieving directory listing of "/var/www/html"...
Status:	Listing directory /var/www/html
Status:	Directory listing of "/var/www/html" successful
Status:	Disconnected from server

Enter image description here

ubuntu@ip-123-45-6-78:~$ chmod 775 -R /var/www/html
chmod: changing permissions of '/var/www/html': Operation not permitted
chmod: cannot read directory '/var/www/html': Permission denied
ubuntu@ip-123-45-6-78:~$ su root
Password:
root@ip-123-45-6-78:/home/ubuntu# cd /
root@ip-123-45-6-78:/# chmod 775 -R /var/www/html
root@ip-123-45-6-78:/# cd /var/www
root@ip-123-45-6-78:/var/www# ls -al
total 12
drwxr-xr-x  3 root     root     4096 Apr 21 07:34 .
drwxr-xr-x 14 root     root     4096 Apr 21 07:34 ..
drwxrwxr-x 12 www-data www-data 4096 Apr 21 14:23 html
root@ip-123-45-6-78:/var/www#

Enter image description here

Angelo
answered a year ago
0

My FileZilla is using the ubuntu user. How do I modify the permissions of ubuntu?

root@ip-123-45-6-78:/# whoami
root
root@ip-123-45-6-78:/# su ubuntu
ubuntu@ip-123-45-6-78:/$ whoami
ubuntu
ubuntu@ip-123-45-6-78:/$ cd /var/www/html
ubuntu@ip-123-45-6-78:/var/www/html$ ls -al
total 1892
drwxrwxr-x 12 www-data www-data    4096 Apr 21 14:23 .
drwxr-xr-x  3 root     root        4096 Apr 21 07:34 ..
-rwxrwxr-x  1 www-data www-data     343 Apr 21 14:23 .editorconfig
-rwxrwxr-x  1 www-data www-data     214 Apr 21 14:23 .htaccess
-rwxrwxr-x  1 www-data www-data   11382 Apr 21 14:23 .htaccess.sample
-rwxrwxr-x  1 www-data www-data    1523 Apr 21 14:23 .php-cs-fixer.dist.php
-rwxrwxr-x  1 www-data www-data     101 Apr 21 14:23 .user.ini
-rwxrwxr-x  1 www-data www-data  766543 Apr 21 14:23 CHANGELOG.md
-rwxrwxr-x  1 www-data www-data     650 Apr 21 14:23 COPYING.txt
-rwxrwxr-x  1 www-data www-data    2972 Apr 21 14:23 Gruntfile.js.sample
-rwxrwxr-x  1 www-data www-data   10364 Apr 21 14:23 LICENSE.txt
-rwxrwxr-x  1 www-data www-data   10376 Apr 21 14:23 LICENSE_AFL.txt
-rwxrwxr-x  1 www-data www-data     698 Apr 21 14:23 SECURITY.md
drwxrwxr-x  4 www-data www-data    4096 Apr 21 14:23 app
-rwxrwxr-x  1 www-data www-data     150 Apr 21 14:23 auth.json.sample
drwxrwxr-x  2 www-data www-data    4096 Apr 21 14:23 bin
-rwxrwxr-x  1 www-data www-data    2803 Feb 23 14:14 composer.json
-rwxrwxr-x  1 www-data www-data 1025343 Apr 21 14:21 composer.lock
drwxrwxr-x  4 www-data www-data    4096 Apr 21 14:23 dev
drwxrwsr-x  4 www-data www-data    4096 Apr 23 11:47 generated
-rwxrwxr-x  1 www-data www-data      55 Apr 21 14:23 grunt-config.json.sample
drwxrwxr-x  4 www-data www-data    4096 Apr 21 14:23 lib
-rwxrwxr-x  1 www-data www-data    6957 Apr 21 14:23 nginx.conf.sample
-rwxrwxr-x  1 www-data www-data    1234 Apr 21 14:23 package.json.sample
drwxrwxr-x  2 www-data www-data    4096 Apr 21 14:23 phpserver
drwxrwxr-x  6 www-data www-data    4096 Apr 21 15:59 pub
drwxrwxr-x  7 www-data www-data    4096 Apr 21 14:23 setup
drwxrwsr-x  8 www-data www-data    4096 Apr 23 11:54 var
drwxrwsr-x 75 www-data www-data    4096 Apr 21 14:23 vendor
ubuntu@ip-123-45-6-78:/var/www/html$

Enter image description here

Angelo
answered a year ago
0

Riku_Kobayashi, Thank you so much. I am now an ubuntu user, and I can upload files normally using FileZilla.

The following code hopefully helps someone who has the same problem as me.

ubuntu@ip-123-45-6-78:/$ su root
Password:
root@ip-123-45-6-78:/# usermod -aG www-data ubuntu
Angelo
answered a year 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