I was struggling with this problem. I want to generate a ssh key by Jsch and send it through email. If I want to keep that private key file be able to use, I need to set the file permission, either way through setting PosixFilePermission or chmod 400. But after I send the file through email and after download from that email, the file's permission gets reset. Is there anyway I can achieve that goal?
Asked
Active
Viewed 79 times
0
-
Before sending the file, you could wrap it in a container format that maintains file permissions (a `tar` archive, for example). Then it won't matter what permissions that container file has, the key file will keep the original permissions when it's extracted. – rickdenhaan Aug 05 '19 at 21:41
-
Hello, I tried to java-util-zip zipping the file and send email, but the permission still changed. (I especially set it to write only and took a test, the original file doesn't allow to rewrite, but the file which extract from the compress zip can be rewrite) Could you please give me some advice which API would support that ability to keep the permissions after compressing? Thank you Rick – Rionash Aug 05 '19 at 22:39
-
Maintaining permissions on files in a ZIP file isn't supported everywhere. Apache has the [Commons Compress](https://commons.apache.org/proper/commons-compress/) library that will allow you to call [`setUnixMode()`](https://commons.apache.org/proper/commons-compress/apidocs/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.html#setUnixMode-int-) on your key file, whether that'll actually work depends on the tool used to extract the archive later. – rickdenhaan Aug 06 '19 at 20:38
-
Thank you so much, I'll try that way! – Rionash Aug 09 '19 at 21:04