我想从node js代码(从我的本地机器)访问服务器端终端。我知道如果你想从代码(从node js代码)执行一些终端命令,你可以使用child-process -但是如何连接到服务器端终端并在那里发送一些命令。希望我的问题是清楚的。
发布于 2018-05-03 05:43:01
如果您的服务器中启用了SSH,则可以使用NPM node-ssh package
var path, node_ssh, ssh, fs
fs = require('fs')
path = require('path')
node_ssh = require('node-ssh')
ssh = new node_ssh()
ssh.connect({
host: 'localhost',
username: 'steel',
privateKey: '/home/steel/.ssh/id_rsa'
}).then( function(){
/* your ssh interactions with the server go here */
/* use the node-ssh API to execute commands, upload files... */
})https://stackoverflow.com/questions/50143577
复制相似问题