begin
# Does not seem to correctly set permissions on open
# https://stackoverflow.com/questions/7713850/unable-to-create-file-with-correct-permissions-using-netssh-library
filehandle = @sftp.open!(newauthkeyfile, 'w', :permissions => 0600)
@sftp.fsetstat!(filehandle, {:permissions => 0600})
# Does not take a permissions argument this way
@sftp.file.open(newauthkeyfile , "w" ) do | file |
authkeys=["Dozentenschlüssel", "1234567890"]
authkeys.each do | line |
puts line
file.puts line
wantedsize += line.length + 1
end
end
@sftp.loop
rescue Net::SFTP::StatusException => exception
puts exception.message
puts "ERROR: Can't open authorized_keys for writing! Skipped."
return
end
I have:
(source from https://github.com/proact-de/distkeys with some minor adaptions made during debugging this)
which should produce:
But it produces:
As hexdump:
Just using "puts" to terminal produces the correct result. I bet Net:SFTP overloads the method and it has to do with the SFTP specific implementation.
If you use "Dozentenschlüüssel" instead then two bytes are missing.
I did not check whether the setting permissions issue I worked around in my code is still there or not.