Linux touch permission denied

Touch command. permission denied

I was able to connect to my school server via SSH. I had an assignment in which I was supposed to use the touch command to create a new file. Yet it keeps returning permission denied. Others were able to do the same thing. Though why do I keep getting this error? Below is what was the input from the terminal.

Last login: Tue Aug 23 09:16:18 on ttys000 Dominiks-Air:~ fsociety95$ ssh djaneka1@navajo.dtcc.edu djaneka1@navajo.dtcc.edu's password: Last login: Tue Aug 23 09:16:35 2016 from pool-72-94-210-193.phlapa.fios.verizon.net 

Navajo is Linux shell server provided to staff, faculty, and students. The operating system is RedHat Enterprise Linux 5. Alpine, a Pine replacement, has been provided as a mail client. Run «pine» at the command prompt. This server also provides web space to users. Web pages can be stored in the ~/www directory. This is also accessible by mapping a drive in Windows to \navajo\homepage. The URL for your homepage is http://user.dtcc.edu/~username/. Your home directory is also accessible in Windows by mapping to \navajo\. If something appears broken or missing, please email path@dtcc.edu. Could not chdir to home directory /u/d/j/djaneka1: No such file or directory

-bash-3.2$ touch today touch: cannot touch `today': Permission denied -bash-3.2$ pwd / -bash-3.2$ touch today touch: cannot touch `today': Permission denied -bash-3.2$ 
-bash-3.2$ ls -al total 204 drwxr-xr-x 25 root root 4096 Aug 22 16:50 . drwxr-xr-x 25 root root 4096 Aug 22 16:50 .. -rw-r--r-- 1 root root 0 Aug 3 14:01 .autofsck -rw-r--r-- 1 root root 0 Jan 30 2009 .autorelabel -rw------- 1 root root 2050 Aug 3 14:00 .bash_history drwxr-xr-x 2 root root 4096 May 4 04:14 bin drwxr-xr-x 4 root root 3072 Aug 3 13:57 boot drwxr-xr-x 11 root root 4060 Aug 3 14:02 dev drwxr-xr-x 87 root root 12288 Aug 23 10:05 etc drwxr-xr-x 3 root root 4096 Oct 1 2009 home drwxr-xr-x 13 root root 12288 Jun 1 04:09 lib drwx------ 2 root root 16384 Mar 24 2008 lost+found drwxr-xr-x 3 root root 4096 Oct 1 2009 media drwxr-xr-x 2 root root 0 Aug 3 14:02 misc drwxr-xr-x 4 root root 4096 May 26 2012 mnt drwxr-xr-x 2 root root 0 Aug 3 14:02 net drwxr-xr-x 9 root root 4096 Jan 5 2009 nsr drwxrwxr-x 3 root root 4096 Oct 12 2015 opt dr-xr-xr-x 219 root root 0 Aug 3 14:01 proc drwxr-x--- 12 root root 4096 Apr 22 10:06 root drwxr-xr-x 2 root root 12288 Aug 4 04:02 sbin drwxr-xr-x 2 root root 4096 Oct 1 2009 selinux drwxr-xr-x 2 root root 4096 Oct 1 2009 srv drwxr-xr-x 11 root root 0 Aug 3 14:01 sys drwxrwxrwt 38 root root 4096 Aug 23 10:07 tmp drwxr-xr-x 34 root root 4096 Jun 21 08:29 u drwxr-xr-x 14 root root 4096 Apr 16 2010 usr drwxr-xr-x 24 root root 4096 Apr 16 2010 var -rw------- 1 root root 2865 Dec 16 2008 .viminfo -bash-3.2$ 

Источник

cannot touch ‘1.txt’: Permission denied

прикупил еще один SSD, воткнул в PC, создал раздел, примонтировал и вижу это. похоже, что диск read-only, и хз, почему.

/dev/sdb1 /home/nixman/DATA ext4 defaults,rw 0 3 

ну, круто что тебе это понятно, но о чем речь? добавить ‘user’ ?

Читайте также:  Grub cmdline linux default quiet splash

niXman ★★★ ( 20.10.17 12:17:23 MSK )
Последнее исправление: niXman 20.10.17 12:22:03 MSK (всего исправлений: 1)

можно и так, но тогда для всех пользователей.
обычно так делаю

 sudo chown -R user:user_group /home/nixman/DATA

Deleted ( 20.10.17 12:29:25 MSK )
Последнее исправление: Lifun 20.10.17 12:32:32 MSK (всего исправлений: 2)

мы, наверное, не понял друг-друга.

в самой директории ‘/home/nixman/DATA’ я могу создавать файлы если в нее не смонтирован диск. но как-только монтирую — ничего создать не могу.

примонтируй и давай сюда выхлоп

Во первых как монтируешь? Ибо просто mount это конечно круто, но там тоже надо задавать нужные флаги.

nixman@nixman-pc:~$ ls -all /home/nixman/DATA total 56 drwxr-xr-x 3 root root 4096 oct 20 10:08 . drwx------ 67 nixman nixman 32768 oct 20 12:13 .. drwx------ 2 root root 16384 oct 19 16:12 lost+found 
nixman@nixman-pc:~$ ls -all /home/nixman/DATA total 40 drwxrwxr-x 2 nixman nixman 4096 oct 20 12:37 . drwx------ 67 nixman nixman 32768 oct 20 12:13 .. 

Источник

Create file in folder: permission denied

I have a problem copying files to a directory on Ubuntu 12.04. I create a directory in the home directory so that the path where I want to copy to is:

francisco-vergara@Francisco-Vergara:/home/sixven/camp_sms/inputs$ touch test_file.txt touch: can not make `touch' on «test_file.txt»: permission denied 

I can not copy files directly in that directory. How can I assign permissions with the chown & chmod commands to copy the files? I do not know which user and group to use.

From what you have copy-pasted, you are running touch as user francisco-vergara , but your directory is in /home/sixven is that really the home of user francisco-vergera or does it belong to a sixven user ? You should clarify what you want to do exactly. Write in another user’s home ? Share that directory among a group ?

3 Answers 3

First of all you have to know that the default permission of directories in Ubuntu is 644 which means you can’t create a file in a directory you are not the owner.

you are trying as user:francisco-vergara to create a file in a directory /home/sixven/camp_sms/inputs which is owned by user:sixven .

So how to solve this:

    You can either change the permission of the directory and enable others to create files inside.

sudo chmod -R 777 /home/sixven/camp_sms/inputs 
sudo chown -R francisco-vergara:francisco-vergara /home/sixven/camp_sms/inputs 

So i advise you to use Option 1.

Or if this directory will be accessed by both users you can do the following trick:

change ownership of the directory to user:francisco-vergara and keep the group owner group:sixven .

sudo chown -R francisco-vergara /home/sixven/camp_sms/inputs 

Like that both users can still use the directory.

But as I said you before It’s easiest and more efficient to use option 1.

Источник

cannot touch -m a writable file

Can someone explain why I get permission denied when running touch -m on this file even though it is group writable and I can write to the file fine.

~/test1-> id uid=1000(plyons) gid=1000(plyons) groups=1000(plyons),4(adm),20(dialout),24(cdrom),46(plugdev),109(lpadmin),110(sambashare),111(admin),1002(webadmin) ~/test1-> ls -ld .; ls -l drwxrwxr-x 2 plyons plyons 4096 Feb 14 21:20 . total 4 -r--rw---- 1 www-data webadmin 24 Feb 14 21:29 foo ~/test1-> echo the file is writable >> foo ~/test1-> touch -m foo touch: setting times of `foo': Operation not permitted ~/test1-> lsattr foo -------------e- foo ~/test1-> newgrp - webadmin ~/test1-> id uid=1000(plyons) gid=1002(webadmin) groups=1000(plyons),4(adm),20(dialout),24(cdrom),46(plugdev),109(lpadmin),110(sambashare),111(admin),1002(webadmin) ~/test1-> touch -m foo touch: setting times of `foo': Operation not permitted ~/test1-> echo the file is writable >> foo ~/test1-> 

3 Answers 3

 The utime() system call changes the access and modification times of the inode specified by filename to the actime and modtime fields of times respectively. If times is NULL, then the access and modification times of the file are set to the current time. Changing timestamps is permitted when: either the process has appropri‐ ate privileges, or the effective user ID equals the user ID of the file, or times is NULL and the process has write permission for the file. 

So, to change only the modification time for the file ( touch -m foo ), you’d need to either be root , or the owner of the file.

Читайте также:  Настройка клиента dhcp linux

Being able to write to the file only gives you permission to update both the modified and access times to the current time; you can not update either separately, nor set them to a different time.

Источник

Why can I ‘touch’ a write-protected file?

Does touch change permissions, touch the file, and change permissions back? Why would it do that? Given this behavior, if I really want to protect a file so that I (my user) will never (unintentionally) change, remove or change its timestamp in the future — how can I do it? (Sorry, not strictly programming-related, but slightly, and probably of interest to many programmers.)

5 Answers 5

From the touch (coreutils) documentation:

If changing both the access and modification times to the current time, `touch’ can change the timestamps for files that the user running it does not own but has write permission for. Otherwise, the user must own the files.

That only seems to cover ownership — the question was about write access so I believe @objlass has it right — timestamps are held in the directory entry, not the file, so write access to the directory is enough to change them.

That could be a little clearer. Is it saying that if you can touch files with either w-perms or ownership?

The execution permissions of the directory that the file contains dictates the ability to delete or modify the inode information for the entry in the directory that is associated with the file.

As the comment below indicates I have glossed over the technical reason but instead offered a reasoning why the behavior might not be as expected. Since you can execute in the directory there are a number of things you can do to tinker with the file and I am going to leave it at that.

If you want to stop anyone but root from modifying a file the best method is to use the chattr +i filename on the file. Even root will not be able to perform any actions on it without running chattr -i on it. This applies to Linux so YMMV.

Читайте также:  Linux executable file extensions

Could the user touch readonly files that are owned by someone else if said user has execute permissions on the directory?

You can delete a file that you cannot read in a directory where you have execute permission. There can be a lot of experimentation and variations done but the fact remains permissions of files are not the definitive end all be all indication of the actions you are authorized to perform.

Execute permission on the directory is required in order to specify a file name in the directory, but that alone does not permit «touch». For «touch», you must be the owner of the file (as here), or have write permission, or be root.

-1 misinformation. Execute on a directory controls traversal/cd/search, not delete/modify permissions for the file inodes. That is determined by the Write permission on the directory. The OP never bothered to specify his directory permissions. This behaviour implies that the directory had +w for him.

Here’s the relevant output from : strace «touch test.txt»

open("test.txt", O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK|O_LARGEFILE, 0666) = -1 EACCES (Permission denied) futimesat(AT_FDCWD, "test.txt", NULL) = 0 

It indeed gets a «Permission denied error» on the open(2) system call regarding EACCES. See relevant section in utimes(2) man page.

However, it does succeed in updating the timestamp using the futimesat(2) system call.

As others have indicated, it looks like the directory permissions hold the rights to update access/moficiation timestamps.

You can, however change the attribute of a file to immutable using:

Note: Only root can do this, and it’s a very harsh way to disable access to files. But in extreme cases, it can be useful. In addition, this is an ext2/3/4 feature, not available on other filesystems as far as I know.

You beat me to it Tom, «not programming related» my hat 🙂 OP might like to check the EACCES paragraph in the man page for utimes(2) or futimesat(2), not to mention the souce for touch(1).

You can update the modification time if you own the file, regardless of write permission. (It is not related to any permission on the directory.)

Only a process with the effective user ID equal to the user ID of the file, or with write access to the file, or with appropriate privileges may use futimens() or utimensat() with a null pointer as the times argument or with both tv_nsec fields set to the special value UTIME_NOW . Only a process with the effective user ID equal to the user ID of the file or with appropriate privileges may use futimens() or utimensat() with a non-null times argument that does not have both tv_nsec fields set to UTIME_NOW and does not have both tv_nsec fields set to UTIME_OMIT . If both tv_nsec fields are set to UTIME_OMIT , no ownership or permissions check shall be performed for the file, but other error conditions may still be detected (including [EACCES] errors related to the path prefix).

Источник

Оцените статью
Adblock
detector