Amazon EC2 Chmod-ed etc to 644 - amazon-ec2

Hy guys,
I chmod-ed /etc/ to 644 while logged in as ec2-user and now i cannot access /etc
" -bash: cd: etc/: Permission denied "
How can i get my permission back? I cannot login as root through putty - it says to log in as ec2-user.
I am a rookie in linux and AWS.

To get a root access log-in as ec2-user, then type sudo su - to change the user to root. After that you can change directory permissions back.
Also you can just use sudo chmod under ec2-user.

Related

FIle could not be opened in append mode: failed to open stream: Permission denied laradock

I'm setting up laradock (Setup for Multiple Projects) following the official documentation from the Laradock in my local machine.
After installation I installed the laravel through workspace container bash. I did configured the config file for the app in nginx/sites/ directory and in /etc/hosts file.
While visiting the development url I'm getting the following error message:
The stream or file "/var/www/laravel-api/storage/logs/laravel.log" could not be opened in append mode: failed to open stream: Permission denied
This worked for me:
chown -R www-data:www-data "project foldername"
If you are still facing the issue even after changing the permission and owner of file, just check for the OS of you Linux server.
Login to your server
$ ssh user#server-ip
check your OS running on linux server
$ cat /etc/os-release
//output
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
If it is CentOS, you need to disable Security-Enhanced Linux (SELinux) if enabled.
Check for SELinux status
$ sestatus
If it is enabled, then
$ setenforce Permissive
Or
$ sudo setenforce 0
Have a good day!
you have to enter the workspace first by typing "docker-compose exec workspace bash"(without quotes)
To give a write permission to a single file,
chmod -R 777 /var/www/laravel-api/storage/logs/laravel.log
or
chmod -R 777 /var/www/laravel-api/storage/logs
or
sudo chmod -R 777 /var/www/laravel-api/storage/logs/laravel.log
when the same error appears but different folders or files, do the same thing only change the folder name
example :
chmod -R 777 /var/www/laravel-api/storage/logs
chmod -R 777 /var/www/laravel-api/storage/framework/views
chmod -R 777 /var/www/laravel-api/storage/framework/sessions
If you aren't running your application as root on your web server, then it wont have write access based on the permissions you've provided.
Checked from workspace container bash. storage/logs/ directory has drwxr-xr-x 2 root root 4096 Aug 1 07:37 logs
The error is complaining about permission denial for opening in append mode - it doesn't have permission to write to the file, only root does.
What you need to do is make your web server group the owner of the storage directory:
chown -R www-data:www-data /var/www/laravel-api/storage/
The www-data can be switched out for whatever group your web server is associated with.
To avoid completely repeating an amazing and complete answer, I recommend you give this answer a read:
How to set up file permissions for Laravel?
Give group write access to /storage/logs/
sudo chmod g+w storage/logs
You need to run the following command. It works for me:
step 1:
sudo chmod -R +rwX .
step 2:
sudo chown -R $(whoami) .

Permission denied on file transfer

I have a new instance and everything was going fine, I have the site installed and transferred over my database and uploaded most my wordpress file to the server.
But towards the end of my upload, files stopped being uploaded and I keep getting the message
***Error: Directory /opt/bitnami/apps/wordpress/htdocs/wp-content/uploads/2017/01: no such file or directory
Command: cd "/opt/bitnami/apps/wordpress/htdocs/wp-content/uploads/2017"
Response: New directory is: "/opt/bitnami/apps/wordpress/htdocs/wp-content/uploads/2017"
Command: mkdir "01"
Error: mkdir /opt/bitnami/apps/wordpress/htdocs/wp-content/uploads/2017/01: permission denied
Command: mkdir "/opt/bitnami/apps/wordpress/htdocs/wp-content/uploads/2017/01"
Error: mkdir /opt/bitnami/apps/wordpress/htdocs/wp-content/uploads/2017/01: permission denied***
I've tried changing the permissions to 755 or 644 but get this error
***Status: Setting permissions of '/opt/bitnami/apps/wordpress/htdocs/wp-content/uploads/2017/07' to '644'
Command: chmod 644 "07"
Error: set attrs for /opt/bitnami/apps/wordpress/htdocs/wp-content/uploads/2017/07: permission denied***
Video file transfer: https://www.screencast.com/t/d8BbFnxkp
Video permission fail: https://www.screencast.com/t/2XBr6zwqd
I'm just puzzled why the other transfers worked
Thanks for your help.
I found this solution that appears to work.
sudo chown -R bitnami:daemon /opt/bitnami/apps/wordpress/htdocs/wp-content/uploads
sudo chmod -R 775 /opt/bitnami/apps/wordpress/htdocs/wp-content/uploads
Then, you can try to upload and check if it works. If it doesn't, you can try doing this instead:
sudo chown -R daemon:daemon /opt/bitnami/apps/wordpress/htdocs/wp-content/uploads
In my case I had this problem while publishing my application from JetBrains Rider to Ubuntu server via SFTP. As there is no way to use sudo, the easy solution was to set publish folder ownership for user, specified in ssh connection for SFTP.
sudo chown -R username:username /var/www/your-app-publish-folder
Or, if you are already logged in under this user on server:
sudo chown -R $USER:$USER /var/www/your-app-publish-folder

Get permission to work with files on my Amazon EC2 Ubuntu server using FTP-WinSCP

I have an Ubuntu server on Amazon, I installed everything for working with it (php, mysql, phpmyadmin, apache..), The problem is that I cant move around or edit files using the FTP.
I get the error message:
Permission denied.
Error code: 3
Error message from server: Permission denied
from my WINSCP.
The only way I can trancefer/edit file is using 'putty' with the sudo/nano command.
I found a lot of information about this on google, but there are no updated soulution I can find. Linux isn't my usual work-space.
How do I get the permissions working for the WINSCP ?
A lot of answers say to change permissions on /var/www/ ... however AWS shortcuts out of the WWW folder and into the /var/app/current/ directory. If all else fails try:
sudo chown -R -v ec2-user /var/app/current/
On Ubuntu image in AWS, default user is ubuntu. Instead of using system folders like /var/... better to use /home/your_folder. Then change the ownership using {chown} command. For eg.
$ sudo chown -R -v ubuntu /home/your_folder/
This will change the ownership of 'your_folder' and contents inside it from 'root' user to 'ubuntu'. Then Winscp should be able to upload/delete/create files using SFTP/FTP etc..
I had the same issues. The solution is: You can solve this by changing WordPress ownership type:
sudo chown -R www-data:ubuntu /var/www/wordpress
Then, Change the right permission for the particular files and directories, type command
sudo find /var/www/wordpress/ -type d -exec chmod 755 {} \;
sudo find /var/www/wordpress/ -type f -exec chmod 644 {} \;
Apart from this, set the following important files to chmod 600 so that only the owner can fully read and write access to these files:
sudo chmod 600 /var/www/wordpress/wp-config.php
sudo chmod 600 /var/www/wordpress/.htaccess
Then everything will work. You will be able to access your wordpress files
for me using free tier from cloud providers will not give you root access, to fix this you have to change folder permission from SSH or try this solution
OS: windows 10 Pro
Open WinSCP instead of SFTP you select SCP go to advance settings click on SCP/Shell and change the shell option to sudo su -
Now you will be able to get permission.
Change file permision by command chmod 777 /var/app/current/ and transfer files to the directory

How to change the Owner a Group of a file using the terminal?

I'm trying to change the owner of a folder (myFolder) and all its content to 30061 with this line:
chown -Rv 30061 myFolder
But I get this message for some files
chown: changing the owner of
myFolder/default/files/languages/es_smDXmy4sxGaYZuUOuV1ftDL7hg824v5FxIsQ2QqZcJM.js?:
Action denied
This files has the owner set to 20003
If I try to change the permission with:
chmod -R 777 myFolder*
I get the same error message:
chmod: changing permissions of
myFolder/default/files/languages/es_smDXmy4sxGaYZuUOuV1ftDL7hg824v5FxIsQ2QqZcJM.js?:
Action denied
Modern Unix/Linux does not usually allow non-root users to "give away" files. In some cases, there's a kernel tunable to revert to older behavior and allow this, but it's usually not a good idea from a security standpoint. Either run the chown as root, or setup sudo to allow the necessary privilege escalation.
If you are not the owner you'll need super-user rights. Prepend your command with a sudo, for example. Otherwise log in as root and run it as root.
Exception: immutable files.

SCP File command as non-root user on the server

I have some files to upload. Usually to edit anything while logged in the server I must precede the command with sudo. That is known.
How do I send a file then as "admin" instead of "root" when I have disabled root login.
scp path\to\file admin#myaddress.com:/var/www/sitename/public/path/
PERMISSION DENIED
In my opinion, either you should give permissions to the admin user or scp your file to /tmp/ and then sudo mv /tmp/yourfile /var/www/sitename/public/path/.
There is no sudo option when we are using scp command from local to server.
Each user will have upload permission to its own folder in home directory ex. home/xxxxuser so use as below:
scp file_source_here xxxuser#yourserver:/home/xxxuser/
Now you can move file from this folder to your destination.
I suggest these two commands as it works in a bash script.
Move the file to tmp as suggested.
scp path\to\file admin#myaddress.com:/tmp
Assuming admin user can do sudo. The ssh option -t allow you to do sudo command.
ssh -t admin#myaddress.com 'sudo chown root:root /tmp/file && sudo mv /tmp/file /var/www/sitename/public/path/'

Resources