diff options
author | Joey Hess <joey@kitenet.net> | 2014-01-03 17:44:12 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2014-01-03 17:44:12 -0400 |
commit | d79d27b97a485d44ffd14e7915a773537dd13d53 (patch) | |
tree | 999030eb1b2a0aa756198ad5636dc95e0b198d95 /Utility | |
parent | 69882c022f0ae9619ee7f51c087990724f4d4099 (diff) |
assistant: Ensure that .ssh/config and .ssh/authorized_keys are not group or world writable when writing to those files, as that can make ssh refuse to use them, if it allows another user to write to them.
Diffstat (limited to 'Utility')
-rw-r--r-- | Utility/SshConfig.hs | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/Utility/SshConfig.hs b/Utility/SshConfig.hs index b7068f48d..d6cd32078 100644 --- a/Utility/SshConfig.hs +++ b/Utility/SshConfig.hs @@ -10,6 +10,7 @@ module Utility.SshConfig where import Common import Utility.UserInfo import Utility.Tmp +import Utility.FileMode import Data.Char import Data.Ord @@ -117,7 +118,19 @@ changeUserSshConfig modifier = do c <- readFileStrict configfile let c' = modifier c when (c /= c') $ - viaTmp writeFile configfile c' + viaTmp writeSshConfig configfile c' + +writeSshConfig :: FilePath -> String -> IO () +writeSshConfig f s = do + writeFile f s + setSshConfigMode f + +{- Ensure that the ssh config file lacks any group or other write bits, + - since ssh is paranoid about not working if other users can write + - to one of its config files (.ssh/config and .ssh/authorized_keys) -} +setSshConfigMode :: FilePath -> IO () +setSshConfigMode f = modifyFileMode f $ + removeModes [groupWriteMode, otherWriteMode] sshDir :: IO FilePath sshDir = do |