Function: Register a Public Key on on SSH Host

by Simon Sparks · 21 March 2026

To use this function add it to the class library file named PluginSSHService.ts

GitHub Repository: https://github.com/SimonSparksUK/Orchestrator

Filename: PluginSSHService.ts

Description: Orchestrator Function to register a Public Key on an SSH Host

Public Function: registerPublicKey

public registerPublicKey(strSSHHostFQDN: string, strUsername: string, strPassword: string): void {
    try {
        let objSSHSession: SSHSession = new SSHSession(strSSHHostFQDN, strUsername);
        objSSHSession.connectWithPassword(strPassword);

        let intErrorCode: number = objSSHSession.putFile("/usr/lib/vco/app-server/conf/vco_key.pub", "/tmp");

        if (intErrorCode != 0) {
            objSSHSession.disconnect();

            this.objLogger.info(`Registration of Automation Orchestrator server public key on '${strSSHHostFQDN}' for user '${strUsername}' failed (file transfer): ${objSSHSession.error}`);
        }

        let strCommandLine: string = `cd ; mkdir -p .ssh ; cat /tmp/vco_key.pub >> ~/.ssh/authorized_keys ; rm -f /tmp/vco_key.pub`;

        objSSHSession.executeCommand(strCommandLine, true);

        objSSHSession.disconnect();

        if (objSSHSession.error) {
            this.objLogger.info(`Registration of Automation Orchestrator server public key on '${strSSHHostFQDN}' for user '${strUsername}' failed (command): ${objSSHSession.error}`);
        } else {
            this.objLogger.info(`Registration of Automation Orchestrator server public key completed on '${strSSHHostFQDN}' for user '${strUsername}'`);
        }
    } catch (objException) {
        this.objLogger.info(`Registration of Automation Orchestrator server public key on '${strSSHHostFQDN}' for user '${strUsername}' failed. ${objException}`);
    }
}

Discover more from Cloud Build Tools

Subscribe to get the latest posts sent to your email.

You may also like