1

Let us consider that I have a file /home/base/alpha.txt with permission 777 i.e. -rwxrwxrwx in user@host. Now, from system host1 as user1 i.e. user1@host1, I try to pull the file mentioned above using the following command:

scp user@host:/home/base/alpha.txt .

As per file permissions 777, everyone has read-write-execute permission i.e. anyone should be able to read, write and execute the mentioned file. Why does Unix ask for the user@host password then?

1
  • 2
    Not everyone in the world, just every process on host. But you're on host1, you have to connect to host and ask some process on host to read it and copy it to you, which needs authentication. Also, you're not using Unix. Apr 16, 2019 at 10:13

1 Answer 1

5

The file permissions apply on the host. The file still needs to be made visible externally; you’re using SSH (via scp) to do so, and it’s SSH which is asking for your password. This happens before anything involving the target file at all; the SSH server authenticates the connecting user, and only after that’s completed (successfully) is scp involved on the target host and the target file accessed.

If you want passwordless SSH access, you can set up keys to do so.

Incidentally, since you’re logging in as user on host, the relevant permissions for alpha.txt are only those which apply to user. If user is the owner of alpha.txt, alpha.txt only needs to be readable by its owner.

5
  • I understand that it is SSH that asks for the password but I think that this line "the relevant permissions for alpha.txt are only those which apply to user" is wrong. Does not the LSB in 777 apply for everyone and MSB for the owner of the file? Apr 16, 2019 at 9:59
  • 1
    The first triple applies to the owner, the middle triple to the group, and the last triple to everyone else; but you haven’t specified what user’s relationship to alpha.txt is, which is why I wrote that the relevant permissions are those which apply to user (not “owner”, the specific user you’re accessing the file as). If user is alpha.txt’s owner, then the owner permissions apply; if user is a member of alpha.txt’s owning group, then the group permissions apply; otherwise, the other permissions apply. Apr 16, 2019 at 10:02
  • user is the owner of the file. I did not mention it due to the irrelevancy of relationship when the permission is set as 777 Apr 16, 2019 at 10:12
  • 1
    @daedalus_hamlet when the password is being requested, SSH hasn't even started to look at the file. Only after the user is authenticated will SSH look for the file and check permissions. So the permissions being 777 are absolutely irrelevant until your user is authenticated with SSH.
    – muru
    Apr 16, 2019 at 10:26
  • @muru your comment clarifies it. Thanks. Apr 16, 2019 at 10:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .