class Publickey < ApplicationRecord belongs_to :user after_commit :do_refresh, on: [:create] # Updates /home/git/.ssh/authorized_keys # called when something added/?/etc to publickeys table def do_refresh Rails.logger.debug "DB8 publickey.rb:def self.refresh called" if Publickey.all.size > 0 File.write('/tmp/authorized_keys', Publickey.pluck(:data).join("\n") ) system("sudo -u #{self.user.token} cp /tmp/authorized_keys /home/#{self.user.token}/.ssh/authorized_keys") File.delete('/tmp/authorized_keys') end end end