我有一个文件调用.deploy,这里是内容
#!/bin/bash
ssh root@201.189.46.12
要登录到我的云服务器。我这样做是因为我不想记住api。所以我要去我的服务器
bash .deploy
但是我可以使用其他替代方法来代替bash吗?其他开发人员可能会使用其他操作系统。
答案 0 :(得分:0)
尽管我没有看到很多有关如何使用其requestShell
函数的文档,但这可以使用node-ssh进行工作:
var path, node-ssh, ssh, fs
fs = require('fs')
path = require('path')
node-ssh = require('node-ssh')
ssh = new node-ssh()
ssh.connect({
host: '(hostname or ip address goes here)',
username: 'root'
/* can also use privateKey parameter to specify a RSA key file instead of password */
password,
tryKeyboard: true,
/* workaround bug in ssl2 https://github.com/mscdex/ssh2/issues/604 */
onKeyboardInteractive: (name, instructions, instructionsLang, prompts, finish) => {
if (prompts.length > 0 && prompts[0].prompt.toLowerCase().includes('password')) {
finish([password])
}
}
})
})
.then(function() {
ssh.requestShell()
})
替代simple-ssh:
var SSH = require('simple-ssh')
var readline = require('readline')
var rl = readline.createInterface({
input: process.stdin
output: process.stdout
})
var ssh = new SSH({
host: '(hostname or ip address goes here)'
user: 'root'
pass: 'your password'
})
rl.on('line', function(input) {
ssh.exec(input, {
out: function(stdout) {
console.log(stdout)
}
err: function(stderr) {
console.log(stderr)
}
}).start()
}).on('close', function() {
process.exit(0)
})