mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-24 23:33:33 +01:00
Make sure, .ssh directory and authorized_keys file are kept at correct permissions
This commit is contained in:
parent
99eeb08419
commit
be7ce72ebe
1 changed files with 10 additions and 1 deletions
|
@ -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())
|
||||
|
|
Loading…
Reference in a new issue