我一直在寻找这个问题,却找不到合适的解决方案。
这是我的代码库。我已经在private key
和""" Private Key """
下传递了私钥。但是两种方法都一直给我这个错误。在本地通过以下所示的键正确运行时。
Private Key
。
错误: 2019-01-03T05:17:36.999Z dc94ff03-0f16-11e9-8f33-ad2618790c4d错误:无法解析privateKey:不支持的密钥格式
at Client.connect (/var/task/node_modules/ssh2/lib/client.js:230:13)
at SSH.start (/var/task/node_modules/simple-ssh/lib/ssh.js:214:19)
at exports.handler (/var/task/simplessh.js:72:4)
END RequestId:dc94ff03-0f16-11e9-8f33-ad2618790c4d
REPORT RequestId:dc94ff03-0f16-11e9-8f33-ad2618790c4d持续时间:153.03 ms计费持续时间:200 ms内存大小:128 MB使用的最大内存:22 MB
RequestId:dc94ff03-0f16-11e9-8f33-ad2618790c4d进程在完成请求之前已退出
代码:
const SSH = require('simple-ssh');
exports.handler = (event, context, callback) => {
var ssh = new SSH({
host: '00.000.000.000',
user: 'ubuntu',
port: 2202,
key : `-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAhDnPYbgBuZycHnei27TAKJ04FL7lmA+RwHD+Sre/swcZiAwe
OJDRlLsTJ/THis is not fully private key
veEWoxlRxTfRpR8/X4uuEeBJAGZnW99WLYoFBnWfFCxtNbyQwwSwwoyQxe13KAwC
-----END RSA PRIVATE KEY-----`
});
const subdomainName = 'staging-test2';
var migration = "&& php artisan tenant:migrate --subdomain=" + subdomainName + " --seed >> /tmp/seed.log";
var jsonstring = '{"company_name":"Apple","company_address":"123 Street Name","company_city":"Mexico","company_postcode":"3156","company_phone":"+41231321321","company_mobile":"+45564654654","company_fax":"+546465465465","company_email":"info@newtenant.local","company_country":"US","company_office":"Mexico","company_main_contact":"Ash Sutherland","company_email_domain":"newtenant.local"}'
var endStringStoredRegExWithEscape = undefined;
var re = new RegExp('\"', 'g');
endStringStoredRegExWithEscape = jsonstring.replace(re, "\\\"") // /"/g saved regex
var concatWithlog = "&& php artisan tenant:new:seed --subdomain=" + subdomainName + " --data=" + "\"" + endStringStoredRegExWithEscape + "\"" + " >> /tmp/seed.log";
var re2 = new RegExp("//", 'g');
var serverArtisanPath = "cd /var/www/ib-dev-be/".replace(re2,"\\/"); // "//g"
var currentPathCmd = "&& pwd";
const seed = concatWithlog;
var command = serverArtisanPath + currentPathCmd + migration + seed;
console.log("*********************************");
console.log("serverArtisanPath : ",serverArtisanPath);
console.log("migration : ", migration);
console.log("seed : ",seed);
console.log("*********************************");
ssh.exec(command, {
out: console.log.bind(console)
}).start();
};