1

I have a use case where my folder on the linux server needs to have its permissions opened up so I can use a sudo account to move files from my folder to shared folders. What then happens is often times I am not the one to log out (ssh connection disconnects) and my home folder permissions stay open. I don't care about the permissions being open except for the fact that when I try to ssh back in, the open folder permissions prevent my key authentication from working and I'm forced to enter a password.

I want to know if I can setup a way to always set my permissions to 700 upon exiting (graceful or otherwise) the ssh session. Alternatively, if there is a way to make key authentication work when my home folder is set to 777 that would also help.

By the way, in case it's helpful, here is what I'm actually trying to do. I use scp to move a locally built .jar from my machine to the home folder on the linux server. I then have to move that .jar from my home folder to a shared folder where the .jar can be executed. To move that .jar to the shared folder I have to use a provided sudo account, however, that sudo account cannot access my home folder unless I open the permissions.

  • Leaving aside the permissions change you're trying to enact for a moment, what are you actually trying to do that requires you to need to change permissions in the first place? It's quite likely someone here can help you avoid the workaround entirely. – roaima May 15 '16 at 19:35
  • I use scp to move a locally built .jar from my machine to the home folder on the linux server. I then have to move that .jar from my home folder to a shared folder where the .jar can be executed. To move that .jar to the shared folder I have to use a provided sudo account, however, that sudo account cannot access my home folder unless I open the permissions. – Serge May 15 '16 at 19:49
1

Using information from your comment, the solution seems to be to fix the underlying issue rather than answer the question you've actually asked.

I use scp to move a locally built .jar from my machine to the home folder on the linux server. I then have to move that .jar from my home folder to a shared folder where the .jar can be executed. To move that .jar to the shared folder I have to use a provided sudo account, however, that sudo account cannot access my home folder unless I open the permissions.

As you have noticed, setting your home directory's permissions to 0777 prevents ssh from working. This is by design. Instead, create a subdirectory to contain your jar file and safely relax the permissions on that directory. Add execute permission to group and others for your home directory so that your sudo account can access through it to the target folder:

chmod 711 "$HOME"`
mkdir -m777 "$HOME/subdir"

At this point, consider as an example that $HOME might be /home/serge. Now, although ls /home/serge fails for your sudo account with a permission issue, it will be able to search through your home directory and into the subdirectory ls /home/serge/subdir.

If your sudo account and your own account have a group in comment - or it can be arranged for them to have a group in common - you can relax group permissions on the subdirectory:

chmod 710 "$HOME"
chmod 770 "$HOME/subdir"
chgrp {whatever} "$HOME/subdir"

Alternatively, transfer the file to /tmp (or /var/tmp) instead of to your home directory and avoid the entire difficulty.

  • I ended up going with the /tmp approach. Setting the home folder to 711 or even 755, the sudo account wasn't able to see subdir. – Serge May 15 '16 at 20:36
  • @Serge the sudo account cannot see your home directory but with executable permission on that and 777 permission on the subdirectory it would be able to get there directly - try ls /home/serge/subdir (or your actual equivalent). I've extended my answer to illustrate this in a little more detail. – roaima May 15 '16 at 21:03
  • Gotcha, that worked, a little annoying that I can't do auto complete but this definitely clarified how permissions work. Thanks. – Serge May 15 '16 at 21:07

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.