创建无密码辅助 ssh 密钥以设置 ssh 隧道

发布于 2024-07-12 07:51:59 字数 132 浏览 6 评论 0原文

我需要创建一个自动设置 ssh 隧道的脚本。 我认为没有密码的专用 ssh 密钥是一个好的开始,但我找不到这是否可能以及如何做到。 该密钥应该具有有限的权限(仅设置隧道),但我自己需要另一个私钥(带有密码)。

谢谢 !

I need to create a script that automatically setup a ssh tunnel. I think that a dedicated ssh key without password is a good start but I couldn't find if this is possible and how to do it.
This key should have limited privileges (only set the tunnel up) but I need another private key (with a password) for myself.

Thanks !

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

撩人痒 2024-07-19 07:51:59

好的,我找到了答案。

首先,ssh-keygen -f theNewPrivateKey 否则它将覆盖旧的私钥。
其次,ssh -i theNewPrivateKey me@mycomputer -i 选项更改用于身份验证的私钥。

现在我可以尝试我的脚本了。


编辑:我的新密钥如何具有有限的权限:

将公钥复制到目标计算机的 $HOME/.ssh/authorized_keys2 文件时,我添加了以下内容:

command="sleep 99999999999" ssh-dss AAAAB3NzaC1kc3MA...
(+ the rest of the key)

那么唯一允许的命令就是永远等待。
由于创建此密钥的目的是创建反向 ssh 隧道,这应该没问题。
然后我创建隧道:

ssh -T -R 7878:localhost:22 -i .ssh/mynewkey  me@myhomecomputer

最后我可以从我的家庭计算机登录:

ssh myworklogin@localhost -p7878

我希望这不会有安全问题。 如果这是一件坏事,请告诉我!

Ok, I've found the answer.

First, ssh-keygen -f theNewPrivateKey otherwise it will overwrite the old private key.
Second, ssh -i theNewPrivateKey me@mycomputer the -i option changes the private key used for the authentication.

Now I can try my script.


Edit: how does my new key has limited privileges:

When copying the public key to $HOME/.ssh/authorized_keys2 file of the target computer, I added this:

command="sleep 99999999999" ssh-dss AAAAB3NzaC1kc3MA...
(+ the rest of the key)

Then the only command allowed is to wait forever.
Since the purpose of creating this key was to create a reverse ssh tunnel this should be fine.
I then create the tunnel:

ssh -T -R 7878:localhost:22 -i .ssh/mynewkey  me@myhomecomputer

Finally I can log from my home computer:

ssh myworklogin@localhost -p7878

I hope that this does not have security issues. If this is a bad thing, please let me know !

情话难免假 2024-07-19 07:51:59

尝试

使用 ssh-keygen

命令。

Try the

ssh-keygen

command.

鯉魚旗 2024-07-19 07:51:59

我遇到过类似的情况,我必须自动同步服务器内容,而不必在 robocopy 脚本中提供密码。

这个链接帮助了我。

I had a similar situation where i had to synch a server content automatically without having to proivide the password in my robocopy script.

This Link helped me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文