javascript - How to connect to external SSH server by node js
问题描述
want to connect to another linux server that need SSH connection directly from my Node JS code and to fire some commands like to stop a service and etc using some npm package like "cmd-npm".
But when I trying to do it I can't handling the password authentication immediately after connecting.
I've tried to using npm ssh2 package but I can't pass commands inside the server only to connect to it.
Is there any ideal solution for my use case?
This is the code:
cmd.get(
`
ssh username@host_ip
cd ..
ls
`, function (err, data, stderr) {
await console.log('the current working dir is : ', data)
if (err) throw await err;
}
);
解决方案
推荐阅读
- elasticsearch - AWS ElasticSearch Java 进程限制
- c++ - 对包含整数的文本文件进行排序,必须逐行进行排序
- apache-kafka - ActiveMQ 在水平扩展方面与 Kafka 有何不同?
- java - NoSuchMethodError:没有虚拟方法 removeValueAsync()
- android - 当我在一个适配器上调用此方法时,RecyclerView notifyDataSetChanged() 会更新两个适配器
- excel - 如何从特定行中提取第一次出现的单词(日期)?
- react-native - 在 React Native 中使用按钮道具导航屏幕时出错
- c# - 是否可以从 OData API 中仅检索某些实体?
- docker - 码头集装箱显示入口点
- java - Javafx 按钮在第一次调用后没有响应(我在任务线程中调用方法)