Change permissions upon uploading with scp
I am uploading files to my shell account using scp. As I need different permissions on the server than on my computer, I'd like to have a way to easily change the permissions upon upload without needing to ssh to the account and change them manually.
If you're copying from a windows machine, you can use WinSCP to copy, and it has an option to set the permissions on the copied files after the upload.
If not, I think your only choice is to execute a chmod on the server after the upload, which you could do remotely with an ssh command:
scp /path/to/file server:/server/path/to/file
ssh server chmod 644 /server/path/to/file
My preferred working solution would be to use rsync
instead:
Replace:
scp /path/to/file server:/server/path/to/file
With:
rsync --perms --chmod=u+rwx,g+rwx,o+rwx /path/to/file server:/path/to/file
This prevents you from authenticating twice. There are also a lot of other options with rsync which would probably add value such as being able to preserve owner, group, etc.