3

I am writing a script which will SSH into a remote server and execute some commands. The problem I am facing is that the commands are altering file permissions on the remote server which is unintended.

What I normally do, is to ssh to the server (thus opening a login shell) and execute the command manually with umask value set to 0007 (umask 0007 is included in .bash_profile of the remote server, and is thus the default value for the login shell).

Assume the command is called some-command. It looks to me as if ssh executes all commands with a default umask value of 0022 if the <command> option is supplied.

$ ssh user@ip.address "umask && some-command"
0022

I was thinking of prepending the command with umask 0007 as below, which seems to work:

$ ssh user@ip.address "umask 0007 && umask && some-command"
0007

But is there a clean way to do this? Perhaps by specifying an option with ssh?

4

0 回答 0