1
0
mirror of https://github.com/go-gitea/gitea.git synced 2024-12-22 17:34:03 +03:00

Make sure, .ssh directory and authorized_keys file are kept at correct permissions

This commit is contained in:
Sebastian Jackel 2014-08-07 10:00:57 +02:00
parent 99eeb08419
commit be7ce72ebe

View File

@ -69,7 +69,7 @@ func init() {
// Determine and create .ssh path.
SshPath = filepath.Join(homeDir(), ".ssh")
if err = os.MkdirAll(SshPath, os.ModePerm); err != nil {
if err = os.MkdirAll(SshPath, 0700); err != nil {
log.Fatal(4, "fail to create SshPath(%s): %v\n", SshPath, err)
}
}
@ -155,6 +155,15 @@ func saveAuthorizedKeyFile(key *PublicKey) error {
if err != nil {
return err
}
finfo, err := f.Stat()
if err != nil {
return err
}
if finfo.Mode().Perm() > 0600 {
log.Error("authorized_keys file has unusual permission flags: " + finfo.Mode().Perm() + " - setting to -rw-r--r--")
f.Chmod(0600)
}
defer f.Close()
_, err = f.WriteString(key.GetAuthorizedString())