2

It's a question on copying in Linux in general and not just Singularity. I'm trying to recursively copy from remote directory to local directory. In my definition file I have:

scp -r $USER@$HOST_MACHINE:/a/b/c ${SINGULARITY_ROOTFS}/a/b 

The problem is that I need group abc to be able to access /a/b/c on $USER@$HOST_MACHINE. I have this group but not in my active groups on the remote machine. I tried some variance of sg but they all failed. For example:

sg abc scp -r $USER@$HOST_MACHINE:/a/b/c ${SINGULARITY_ROOTFS}/a/b 

Fails because I have abc only in $HOST_MACHINE and not locally. I also tried to use ssh but I need to copy to local directory and not on remote directory.

I was looking in the docs of rsync and scp but could not find a way to add a group into my active groups on remote machines, before copying. Basically I'm looking for a way to do:

scp -active_group abc -r $USER@$HOST_MACHINE:/a/b/c ${SINGULARITY_ROOTFS}/a/b 

How can I copy files from remote to local with a special group?

Basically I could do the following steps:

  • Ssh the remote machine.
  • Wash or use the sg command.
  • Copy from remote to local.
  • exit remote machine.

But the script should be automatic so it's breaks it. I also guess there is a way to do this and I'm just missing it.

2 Answers 2

0

Your local UID/GID names are not guaranteed to match the remote UID/GID names.

But its the UID/GID values that are important in inter-machine transfers. The only UID value that is guaranteed is root - with a UID=0.

If this is a one-off copy, then you will need root access to create a group on the remote machine. So you could - with great care - run your script as root - just to create a new group.

You need to create a group with a GID that matches on both machines [group name is your choice]; presumably this should have the same set of UID's on both machines - [user names are your choice].

Ideally, group names and user names would be the same on the two machines, "for simplicity".

/etc/group is a delimited file listing 'groupname':'x':GID:user1,user2,...

/etc/passwd gives a well-known cross-reference of username,UID

However, this seems to be a very high risk procedure - even if you ran it in a dry-run mode and carefully desk-checked the results.

1
  • Thank you for you reply! But the group already exists in the remote machine and my user has it there. It's just not in the active groups. This means that I can access it if I can see it in the groups output. If it was in my active groups, then it would be solved. The question is how do I make in active?
    – vesii
    Jun 24, 2021 at 7:14
0

If possible, you may just set the set GID bit on the remote machine:

$chmod g+s abc -R /a/b/c 

(or start at /a - depending on your needs). This is a one-time configuration change.

So whatever is done on the remote machine will have abc set as primary group and your scp would work fine as is.

2
  • So basically you are saying, I need to run ssh <hostname> chmod g+s abc -R /a/b/c and then scp?
    – vesii
    Jun 28, 2021 at 7:13
  • Yes. The set GID-bit will ensure that independently of the user's (active) group the actual group of the file will be used for any commands. I hereby assumed that a/b/c already is owned by group abc, though. If not you would need to change the group accordingly (chgrp -R abc /a/b/c). Again: the chmod command would only be run once and then persist. I.e. no need to run it with every scp.
    – FelixJN
    Jun 28, 2021 at 7:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.