与远程主机安全连接并检查
我需要用 C 语言编写一个程序来检查远程文本文件中计算机的 MAC 地址的出现情况。
是否有任何简单易用的 ssh 库允许程序连接到远程主机并检查文件是否包含某些内容?
或者我应该使用
system()
函数在远程主机上运行ssh
和简单命令。它应该是安全的,所以我可能需要使用公钥。是否可以从不同的计算机(每台计算机都有我的程序)使用相同的公钥?
我需要的是检查具有给定 MAC 地址(或其他标识符)的计算机是否被允许执行某些操作。而且此操作应该是远程的,因此我可以远程启用/禁用功能。
I need to write a program in C to check the occurrence of a computer's MAC address in a remote text file.
Are there any simple to use ssh libs which allow a program to connect to a remote host and check if a file contains something?
Or should I use the
system()
function to runssh
and simple commands on the remote host.It should be secure, so probably I need to use public keys. Is it possible to use the same public key from different computers (each with my program)?
What I need is to check if the computer with the given MAC address (or other identifier) is allowed to do something. And this operation should be remote, so I could remotely enable/disable functionality.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
1)我不知道是否简单,但是有 http://www.libssh.org/来自 IIRC,与执行 cURL 的人相同
2) 是的,您可能应该通过 shell 脚本的“系统函数”(或 system/popen,如果您绝对需要在 C 程序中获得结果)来执行此操作,如这会为你省去很多麻烦重新实现事物。
3)公钥,是的;虽然可以在多个主机/用户上重复使用公钥,但这不是良好的安全实践;更好的方法是为每个用户/主机生成一个密钥对,然后将公钥添加到需要连接的计算机上的 .ssh/authorized_keys 中。这意味着撤销密钥只是删除单个文本文件中的一行,而不是为多个主机重新生成密钥。但是,如果它对安全性不敏感,或者在这种情况下安全性根本不重要(!),那么使用单个密钥可能不会太疯狂。也就是说,如果您需要多个客户端来检查单个主机上是否存在;如果没有,请更新您的问题,使其在这方面更加清晰。
1) I don't know if it's simple, but there is http://www.libssh.org/ from, IIRC, the same folks who do cURL
2) Yes, you should probably do this via the "system function" of a shell script (or system/popen, if you absolutely need to have the results inside a C program), as that will save you a great deal of trouble reimplementing things.
3) Public keys, yes; and while it's possible to reuse public keys on multiple hosts/users, it's not good security practice; better would be generating a keypair for each user/host and then adding the public key to .ssh/authorized_keys on the machine you need to connect to. This means that revoking keys is simply removing a line in a single text file instead of regenerating a key for multiple hosts. However, if it's not security-sensitive, or if security just plain doesn't matter in this instance(!), then using a single key may not be too insane. That is, if you need multiple clients to check for existence on a single host; if not, please update your question to be clearer in this regard.