Files
dokploy/packages/server/src/utils/filesystem/ssh.ts
2024-10-05 22:15:47 -06:00

27 lines
521 B
TypeScript

import * as ssh2 from "ssh2";
export const generateSSHKey = async (type: "rsa" | "ed25519" = "rsa") => {
try {
if (type === "rsa") {
const keys = ssh2.utils.generateKeyPairSync("rsa", {
bits: 4096,
comment: "dokploy",
});
return {
privateKey: keys.private,
publicKey: keys.public,
};
}
const keys = ssh2.utils.generateKeyPairSync("ed25519", {
comment: "dokploy",
});
return {
privateKey: keys.private,
publicKey: keys.public,
};
} catch (error) {
throw error;
}
};