First deploy fails in Capistrano 3 with a /var/www/XXX permission error - capistrano

I am running the first deploy to a machine via cap staging deploy. As of Cap3, deploy:setup is no longer needed. Yet, strangely, I get a mkdir permissions error:
INFO[cb348f12] Running /usr/bin/env mkdir -pv /var/www/myapp/shared /var/www/myapp/releases on ec2-xx-xx-xx-xx.us-west-2.compute.amazonaws.com
DEBUG[cb348f12] Command: /usr/bin/env mkdir -pv /var/www/myapp/shared /var/www/myapp/releases
DEBUG[cb348f12] mkdir:
DEBUG[cb348f12] cannot create directory ‘/var/www’
DEBUG[cb348f12] : Permission denied
DEBUG[cb348f12]
DEBUG[cb348f12] mkdir:
DEBUG[cb348f12] cannot create directory ‘/var/www’
DEBUG[cb348f12] : Permission denied
DEBUG[cb348f12]
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing on host ec2-xx-xx-xx-xx.us-west-2.compute.amazonaws.com: mkdir exit status: 1
Of course, I could go an create and chmod that directory myself, but that's not the point. Cap3 is supposed to take care of that itself. I'm confused why it doesn't do that. I should also note that I had this same setup succeed before with another machine (though that was "production" environment).
Here are some basic settings in my deploy.rb:
set :application, "myapp"
set :user, 'ec2-user'

Instead of creating the following directory structure: /var/www/myapp/shared/var/www/myapp/releases
try: /var/www/myapp/releases

EDIT: Re-reading your question, I found that you already know how to create folder on server and set permission.
Cap3 is supposed to take care of that itself. I'm confused why it
doesn't do that
Nope. Cap3 cannot create a folder on server automatically, if the user provided to Cap3 does not have previledges to create the folder. There is no magic here just unix permissions.
In your case the user your have provided ec2-user does not have permission to create folder in /var which causes the error.
Original answer
Check whether /var/www folder exists on your server. If it does not, then create that folder and set its ownership to ec2-user so that Capistrano can create any other folders as necessary during the deployment.
sudo mkdir -p /var/www
sudo chown ec2-user:ec2-user /var/www
With the above commands run, try deploying again with capistrano. Permission error should now be gone.

Related

Permission denied for deploy.sh file in scripts folder

I've getting permission denied upon running scripts/deploy.sh prod in wsl2. Am I supposed to run a chmod command?
I've previously tried to follow this -bash: ./deploy.sh: Permission denied , ERROR: script returned exit code 126 by entering chmod +x scripts/deploy.sh but when I tried running scripts/deploy.sh prod it tells me the file doesn't exist.
Could someone kindly advice? Thank you!
Here's evidence that the file is there:

VS Code: NoPermissions (FileSystemError): Error: EACCES: permission denied

I'm trying to save a file called app.js on a folder called js.
Vs Code pop up this:
Failed to save 'app.js': Unable to write file 'vscode-remote://wsl+ubuntu-18.04/js/app.js'
(NoPermissions (FileSystemError): Error: EACCES: permission denied, mkdir '/js')
I tried:
sudo chown -R user /mnt/c/Users/myUser/Documents/myFolder/proyectFolder
but I still can't save this file.
Try this, fixed it for me
sudo chown -R username path
Example:
sudo chown -R emanuel /home/emanuel/test/
In the SSH terminal:
Recommended :
sudo chmod -R 777 folder_name_where_your_file_exists
or
sudo chmod -R 755 folder_name_where_your_file_exists
this works for me
sudo chown -R $USER:$USER /home/
TLDR;
If you're using a docker container, avoid making files from within the container because the owner and group permissions may cause problems with your editor (in my case VS Code)
I was running docker container for a Django project from Windows Terminal and using VS Code to edit my code.
It is a Linux file (since everything in Linux is a file) permission problem that arises because the files don't have proper user and/or group permissions. So VS Code tries to tell us that.
The problem I found only happened when I created files from within my docker container.
I would run docker exec ... bash
make new files using touch /path/to/file from the container bash
then try to edit those files on VS Code (say urls.py) only to get the scary permissions error preventing the file from saving.
I suspect that making files from within the container embellishes those files with different owner and group settings than your system would default to if you just ran the commands locally (not in the container).
Changing the file permissions with chown -hR and chgrp -hR would do the trick but to avoid the error altogether I stopped making files from within the container.
Try activating polling:
This worked for me during I tried using wsl.
The below is for individual file:
sudo chown yourUserNAme filename
For an entire directory it will be (when you write ls to terminal, you should see your directory to execute this command):
sudo chown yourUserNAme dirName
For recursive (i.e files and folders inside a folder):
sudo chown -R yourUserNAme dirName
Note: yourUserNAme is, if you do pwd under any Documents, you will see the path: /home/jhon/Documents. Here user is jhon.
Run VS Code as administrator and it will fix the problem.
https://answers.microsoft.com/en-us/windows/forum/all/error-in-vs-code-destination-directory-and-says/e70dc626-6b12-4791-a960-8b704e57098d
Install the extension Save as Root in Remote SSH in VS code.
While saving press Ctrl + Shift + P.
This open the command palette.
Search Save as Root
It is a Linux user permissions problem.
you should use the command:
sudo chown -R $USER:$USER.

I am unable make file or directory in Visual Studio Code in Win Subsystem for Linux

I use this guide. When I take the step "Add a source code file", I am shown this report:
Unable to write file 'vscode-remote://wsl+ubuntu-20.04/home/alex/TEST/helloworld/helloworld' (NoPermissions (FileSystemError): Error: EACCES: permission denied, open '/home/alex/TEST/helloworld/helloworld')
I don't know what to do, can some one help me?
The VScode needs permissions thus
Try this command on your WSL terminal
sudo chown -R username /path/to/working/directory
Replace :
'username' with your username and the path of your directory
So I had the same problem and changing ownership via sudo chown -R username <path> did not work for me.
Simple solution!
My issue: Downloaded files for coursera project in zip. Copied files to ubuntu home/taylor/projects folder. and then tried accessing in vscode with code . I received the read error.
Solution:
go to your linux terminal.
Access the folder containing the files you are trying to work on.
For Example: app.py forms.py models.py in the projects folder. got to projects folder.
~/projects ls
app.py forms.py moodels.py routes.py
#they should be white meaning know permissions granted.
grant permissions
a. sudo chmod 777 app.py forms.py models.py routes.py
or
b. sudo chmod +rwx app.py forms.py models.py routes.py #r=read w=write x=execute
Try the above one by #uday Pratap, If not Working try this one's :
sudo chmod -R 777 folder_name_where_your_file_exists
or
sudo chmod -R 755 folder_name_where_your_file_exists

Perl script can't unzip to mounted Windows share - permission denied

I have a simple script that is unzipping a file to a mounted Windows share. It is normally launched as a Postfix alias when a new email arrives, but even when I run it as root I get a permission denied error.
The script is doing this:
if ( </tmp/*.zip> ){
unzip '</tmp/*.zip>' => '</mnt/win/#1.txt>'
or die "unzip failed: $UnzipError\n";
}
As root I can copy files to /mnt/win without a problem, but when this script is launched by Postfix it fails with permission denied.
/etc/fstab looks like:
//srvr1/tmp /mnt/win cifs credentials=/root/.smbcredentials,iocharset=iso8859-1,sec=ntlm 0 0
ls -ld looks like:
drwxr-xr-x 2 root root 196608 Jul 15 17:24 /mnt/win
Files produced by the script are nobody/nogroup, but I'm not sure how I change the permissions of /mnt/win to allow nobody/nogroup to read/write.
cmhod -R ugo+RW /mnt/win
Also gives permission denied. Is there a way to change permissions in /etc/fstab to allow nobody/nogroup?
You need to use this command to change the permissions of folder & files inside it.
sudo chmod -R R+X /mnt/win
If you want to change the user of the file as well which is nobody/nogroup rightnow, you can use this commands :
sudo chown -R username.username /mnt/win/
Here you can choose any user's name e.g. mine is mukesh
sudo chown -R mueksh.mukesh /mnt/win/

Capistrano deploy:setup works but not deploy:check

Testing capistrano with a simple recipe.
$ cap deploy:setup
* executing `deploy:setup'
* executing "sudo -p 'sudo password: ' mkdir -p /u/apps/ [..]
[..]
deploy:setup works as exprected.
However
$ cap deploy:check
* executing `deploy:check'
* executing "test -d /u/apps/[..]
[..]
When running deploy:check I get the following error:
The following dependencies failed. Please check them and try again:
--> You do not have permissions to write to `/u/apps/
[..]
--> `/u/apps/app/shared is not writable [..]
It seems that capistrano is not using sudo while in deploy:check mode.
I don't get it!
While in deploy:setup the whole directory structure was created by capistrano without any issue?
Why capistrano doesn't use sudo as in deploy:check?
I also ran into this issue and it turned out capistrano was creating all of the folders under the <user> group except for the shared folder. SSH onto your server and do a long listing ls -l. If you see - root - root - for the shared folder, you'll just need to update the permissions on the folder:
sudo chown <user> shared
sudo chgrp <user> shared
I ran into the same issue: the trick is to explicitly configure Capistrano not to use sudo.
You can turn that off in your deploy.rb file with:
set :use_sudo, false
If you need to use sudo, how about using the sudo DSL Action Invocation in your commands:
run "#{sudo} apachectl restart"