-when writing the file to the cifs share from linux as root using python 2.7 shutil, no issue
-when writing the file manually using cp as a normal user, no issues
-when using python shutil.copy or copy2 as a normal user:
File "/usr/lib64/python2.7/shutil.py", line 120, in copy
copymode(src, dst)
File "/usr/lib64/python2.7/shutil.py", line 91, in copymode
os.chmod(dst, mode)
OSError: [Errno 1] Operation not permitted: '/mnt/RW_H-drive/file.csv
I was wrong about Debian vs CentOS in the comment above, the Debian system drive died and I'm running my jobs on an enterprise box where the only possibilities are CentOS or SUSE so I can't compare /etc/fstab files. I was trying to mount the share using dir_mode=0777,file_mode=0777 without the uid=xxxx. I don't understand why but when you specify dir_mode and file_mode you get the permissions you expect and can write files to the share manually but using shutil fails with the error above. If you remove dir_mode and file_mode and use user uid=xxxx where xxxx is the user ID of any locally recognozised user (Local,LDAP or NIS) then permissions work as expected manually (cp or touch command etc) and also via python with shutil. I may have had the same issue with Debian when I first setup the fstab file that's why I had this little bell telling me to try uid, nothing else. Bizare thing is that the UID of the user in fstab and the cifs user are unrelated as far as I recall, they don't even have to have the same name. Also both mount lines work when you change files on the share as root user.
Example:
//nasx/sharex/ /mnt/RW_H-drive/ cifs credentials=/root/smbcredentials,_netdev,uid=4321 0 0
Rather than:
//nasx/sharex/ /mnt/RW_H-drive/ cifs credentials=/root/smbcredentials,_netdev,file_mode=0777,dir_mode=0777 0 0
Related
PuTTy AWS no such file or directory
1 - created the ec2 instance at AWS ubuntu
2 - downloaded the key (.pem file)
3 - since Im using windows, I downloaded PuTTy
4 - generate a putty file
5 - Im logged in with Putty (login as: ubuntu
Authenticating with public key "imported-openssh-key"
)
6 - Now need to run:
cd path/to/my/dev/folder/
chmod 400 JupyterKey.pem
ssh ubuntu#11-111-111 -i JupyterKey.pem
# Doesn't work!!
so Im conected to putty and now Im trying open the key(automation.pem) to conect with server AWS to start build my jupyter notebooks
# First attempt
[ec2-user#ip-111-11-11-111 ~]$ cd \Users\pb\Desktop\pYTHON\AWS\server
-bash: cd: UserspbDesktoppYTHONAWSserver: No such file or directory
# Second attempt
[ec2-user#ip-111-11-11-111 ~]$ ssh -i "imported-openssh-key" ubuntu#ec2-54-67-50-191.us-west-1.compute.amazonaws.com
Warning: Identity file imported-openssh-key not accessible: No such file or directory.
The authenticity of host 'ec2-ip-111-11-11-111.us-west-1.compute.amazonaws.com (ip-111-11-11-111)' can't be established.
ECDSA key fingerprint is 11111111111111111111111111111111111111111111111111111.
ECDSA key fingerprint is 11111111111111111111111111111111111111111111111111111.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'ec2-11-111-111.us-west-1.compute.amazonaws.com,11-111-1191' (ECDSA) to the list of known hosts.
Permission denied (publickey).
[ec2-user#ip-172-31-28-150 ~]$
Your cd command did not work because in Linux like files systems the directory seperator is a / and not a . A \ indicates that it's a special character \n for newline or \r for carriage return. Also Linux like file systems are case sensitive.
I say Linux Like because this applies to just about everything except Windows, including the Windows Linux Subsystem, Mac's, Any Unix flavor (Linux, BSD, etc...)
In your second attempt there is no file named imported-openssh-key in your current directory. You need to have the file with the key in the directory you are trying to use ssh with the -i option.
The more typical way to use ssh is in your home directory (You can get to it with cd ~ in most linux like systems) You create a directory called .ssh and store your keys in there and configure a file to know how to access them.
Also I believe there is now native SSH support in Windows, so you probably don't need to jump through the putty hoops anymore.
If the key file isn't on the server you will need to copy it to the Ubuntu server using scp
Hope this helps
I'm setting up a launchctl server to run a python file regularly. So I write a.plist file , auto.sh file and it works well.
However, after I installed Macos Catalina, it failed.
I write "ls -l" in auto.sh to check file permission,
log shows that:
ls: .: Operation not permitted
python3: can't open file 'auto.py': [Errno 1] Operation not permitted
How can I do to fix it? Thank you so much.
here is my code:
auto.sh:
#!/bin/bash
. ~/.bash_profile
conda activate base
cd /Users/gassy/Documents/
ls -l
python3 auto.py
I put such .plist file in /Users/gassy/Library/LaunchAgents/com.gassy.fangzhou.plist
...
<key>Program</key>
<string>/Users/gassy/auto/launch.sh</string>
...
Finally figure it out...
It's a problem related to Catalina new permission system, the /bin/bash need to have the [full disk access].
I think the problem you have is not with Python, but with the file permissions on auto.py or the path leading up to it. What user account is used to run the script? Does that user have the necessary permissions on both those executables and the parent directory? Reason I suspect directory permissions is that ls is failing along with auto.py.
You might have some luck if you move everything out of /Users/gassy/Documents and to another location, perhaps under /opt or /var or similar, and then make sure that the permissions are sane. I know that macos treats some of those directores under /Users/<user> special, sometimes in a less-than-helpful way...
In the spirit of the principle of least privilege:
If you don't want to give bash Full Disk Access you can create a binary wrapper.
Create a C source code file launch.c.
#include <stdlib.h>
int main(void) {
int status = system("/path/to/launch.sh");
int ret = WEXITSTATUS(status);
return ret;
}
Then compile it to launch.
gcc -Wall -o launch launch.c
Grant it Full Disk Access add it the launchd Property List File.
Change the permissions of the file by using the chmod command in your bash script, before running python3 auto.py.
chmox +x auto.py should do, however I would recommend you to read more about it and be specific on your use case.
A modification of #mingxin's solution worked for me: Basically the same steps but instead of giving full disk access to bash in Security & Privacy, give full access to python3 (which on my Big Sur macOS system is in /usr/bin).
I tried to push file into my device using appium.
When I see my device in my windows machine, this is the toor path:
This PC\P00A\Internal shared storage
So if I want to move this file from my machine:
C:\file.txt
I tried using this command:
self.driver.push_file('C:\file.txt', android_path)
But what path should I put instead of android_path ? I am trying to write to sdcard.
The order of parameters is incorrect, according to Push File command documentation it should be:
driver.push_file("/sdcard/file.txt","c:/file.txt")
#remote path local path
You might also be interested in Run Command (adb) extension which allows executing arbitrary ADB commands like:
seetest.run("adb push c:/file.txt /sdcard/file.txt");
I have EV3 Lego Mindstorms and I instaled on it ev3dev operating system. I set the connection with the PC via SSH and using PuTTY I started to "programming". I used the cat > test2.py and wrote this code:
#!/usr/bin/env python3
import ev3dev.ev3 as ev3
motor = ev3.LargeMotor('outA')
motor.run_timed(time_sp = 1000, speed_sp = 500)
I saved the file and initialized it using ./test2.py. I got this output:
-bash: ./test2.py: Persmission denied
What caused it and what should I change?
try this:
sudo python3 test2.py
that will allows you to open almost anything in linux
Use ls -la ./test2.py in order to see the file permissions.
Look at the beginning of the output, you'll see something like this:
-rw-rw-r--
The first - means if is a directory or a file. In this case means that is a file.
Now If you observe the remaining chars there are 3 sets of 3 chars with means the permissions for the owner of the file, the owner group and the last set is for the rest of the users.
We have permissions to read, write and execute and in the example I showed there are read and write permissions for the owner user and the owner group but non permissions for the other users.
As Is said above you can just use sudo every time you execute the script but to run it with root privileges. However I would recommend you change your file permissions and using chmod
sudo chmod +x ./test2.py
This will let you execute the script. Take a look at chmod documentation to learn more: https://help.ubuntu.com/community/FilePermissions
I am trying to upload image through admin page, but it keeps saying:
[Errno 13] Permission denied: '/path/to/my/site/media/userfolder/2014/05/26'
the folders userfolder/2014/05/26 are created dynamically while uploading.
In Traceback, i found that the error is occuring during this command:
In /usr/lib64/python2.6/os.py Line 157. while calling
mkdir(name, mode)
meaning, it cannot create any folder as it doesnot have the permission to do this
I have OpenSuse as OS in Server. In httpd.conf, i have this:
<Directory /path/to/my/site/media>
Order allow,deny
Allow from all
</Directory>
Do I have to chmod or chown something?
You need to change the directory permission so that web server process can change the directory.
To change ownership of the directory, use chown:
chown -R user-id:group-id /path/to/the/directory
To see which user own the web server process (change httpd accordingly):
ps aux | grep httpd | grep -v grep
OR
ps -efl | grep httpd | grep -v grep
This may also happen if you have a slash before the folder name:
path = '/folder1/folder2'
OSError: [Errno 13] Permission denied: '/folder1'
comes up with an error but this one works fine:
path = 'folder1/folder2'
Probably you are facing problem when a download request is made by the maybe_download function call in base.py file.
There is a conflict in the permissions of the temporary files and I myself couldn't work out a way to change the permissions, but was able to work around the problem.
Do the following...
Download the four .gz files of the MNIST data set from the link ( http://yann.lecun.com/exdb/mnist/ )
Then make a folder names MNIST_data (or your choice in your working directory/ site packages folder in the tensorflow\examples folder).
Directly copy paste the files into the folder.
Copy the address of the folder (it probably will be
( C:\Python\Python35\Lib\site-packages\tensorflow\examples\tutorials\mnist\MNIST_data ))
Change the "\" to "/" as "\" is used for escape characters, to access the folder locations.
Lastly, if you are following the tutorials, your call function would be ( mnist = input_data.read_data_sets("MNIST_data/", one_hot=True) ) ;
change the "MNIST_data/" parameter to your folder location. As in my case would be ( mnist = input_data.read_data_sets("C:/Python/Python35/Lib/site-packages/tensorflow/examples/tutorials/mnist/MNIST_data", one_hot=True) )
Then it's all done.
Hope it works for you.
Another option is to ensure the file is not open anywhere else on your machine.
supplementing #falsetru's answer : run id in the terminal to get your user_id and group_id
Go the directory/partition where you are facing the challenge.
Open terminal, type id then press enter.
This will show you your user_id and group_id
then type
chown -R user-id:group-id .
Replace user-id and group-id
. at the end indicates current partition / repository
// chown -R 1001:1001 . (that was my case)
Simply try:
sudo cp /source /destination
Just close the file in case it is opened in the background. The error disappears by itself
The solution that worked out for me here when I was using python 3 os package for performing operations on a directory where I didn't have sufficient permissions and access to got resolved by running the python file with sudo (root) i.e.:
sudo python python_file_name.py
Any other utility that you might also plan on using to chmod or chown that directory would also only work when you run it with sudo.
# file_name.py
base_path = "./parent_dir/child_dir/"
user = os.stat(base_path).st_uid # for getting details of the current user owner of the dir
group = os.stat(base_path).st_gid # for getting details of the current group owner of the dir
print("Present owner and group of the specified path")
print("Owner:", user)
print("Group:", group)
os.chown(base_path, user, group) # change directory permissions
print("\nOwner id of the file:", os.stat(base_path).st_uid)
print("Group id of the file:", os.stat(base_path).st_gid)
os.mkdir(base_path+file_name,mode=0o666)
run the above file with sudo.
sudo python file_name.py
Hope this answer works out for you.
Forever indebted to stackoverflow and the dev community. All hail the devs.