Clear authorized_keys before writing

Was writing both the old content of authorized_keys and the new
tunnel every time a tunnel was created. This essentially made the
file double in size for every new tunnel added.
This commit is contained in:
Anders Pitman 2021-12-03 17:38:06 -07:00
parent e4b6598274
commit 12ec55cf37

View File

@ -197,6 +197,16 @@ func (m *TunnelManager) addToAuthorizedKeys(domain string, port int, allowExtern
newAk := fmt.Sprintf("%s%s %s %s\n", akStr, options, pubKey, tunnelId)
// Clear the file
err = akFile.Truncate(0)
if err != nil {
return "", err
}
_, err = akFile.Seek(0, 0)
if err != nil {
return "", err
}
_, err = akFile.Write([]byte(newAk))
if err != nil {
return "", err