制作 SSH 脚本的最佳方法?

发布于 2024-09-02 00:25:15 字数 998 浏览 4 评论 0原文

我的大学有很多文件(例如过去的论文等),我需要在大学网络上才能访问它们。我使用端口转发 ssh 进入网络,并将浏览器 (Firefox) 设置为通过该端口。我知道用大多数语言编写一些将命令输入终端的东西会很容易,但是我可以使用哪种语言/方法来实现这一点?我希望某种脚本语言可以,但我真的对它们一无所知,但我愿意学习一种只是为了从中获得一点乐趣。

我在 Windows 7 上使用 cygwin 终端,如果这会有所作为的话。

为了解决我的问题:哪种语言最能实现上述效果?不一定是最好的,只是可能并且相对简单易学。我用了“最好”这个词,所以我想我会贴上一个主观标签。

编辑: 以防万一想要做这个精确的事情,我会展示我的解决方案。我最终使用了批处理文件,因为有些事情使 bash 变得更加困难。不管怎样,为了通过 SSH 连接到网络并打开一个新的 Firefox 窗口并更改代理,我只需要打开这个批处理文件并输入我的密码。

cd C:/cygwin/bin
ssh -fND 9001 [email protected]
cd "C:/Program Files/Mozilla Firefox"
firefox -no-remote -P SSH_profile

另存为 .bat

为了使其工作,您需要设置一个名为 SSH_profile(或其他名称)的配置文件,并将连接设置设置为通过端口 9001。该脚本将使用 /cygwin/bin 中的 ssh 命令打开,然后输入在信息中。您输入密码,然后它会转到您的 Firefox 目录,使用这些参数打开一个单独的配置文件并更改连接设置(意味着您可以在一个窗口中查看无法访问的文件以及您不想出现在 Uni 网络上的任何其他内容)在另一个例子中,完成后关闭窗口,

但我想我会分享我的答案,希望有一天能帮助别人。

My university has quite a lot files (like past papers etc) which I need to be on the uni network to access them. I ssh, using port forwarding, into the network and set my browser (Firefox) to go through that port. I know it would be quite easy to write something in most languages that would enter the command into a terminal, but which language/method could I use to make this happen? I expect some sort of scripting language could but I really know nothing about them, but I'd be willing to learn one just to have a little fun with this.

I'm using a cygwin terminal on Windows 7, if that will make a difference.

To neaten up my question: Which language would be best to acheive the above effect? Not necessarily the best, just possible and relatively simple to learn. I used the word best so I suppose I'll put a subjective tag.

EDIT:
Just in case anyway wants to do this precise thing, I'll show my solution. I ended up using a batch file because a few things made the bash more difficult. Anyway, in order to SSH into the network and open a new firefox window with the proxy changed, I just have to open this batch file and enter my password.

cd C:/cygwin/bin
ssh -fND 9001 [email protected]
cd "C:/Program Files/Mozilla Firefox"
firefox -no-remote -P SSH_profile

Save as .bat

In order for this to work you need to set up a profile with name SSH_profile (or whatever) and set the connection settings to go through port 9001. The script will open use the ssh command in /cygwin/bin and enter in the information. You enter your password and then it goes to your firefox directory, uses those arguments which opens a separate profile with the connection settings changed (means you can view unaccessible files in one window and anything else you don't want to be on your uni network in another. Just close the windows when you are done.

Quite a specific case but I thought I'd share my answer in the hope of helping someone, some day.

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

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

发布评论

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

评论(1

临风闻羌笛 2024-09-09 00:25:15

由于您使用的是 cygwin,因此请编写 bash shell 脚本。 。如果您不想依赖 bash,则可以使用 powershell你想要什么,尽管你可能可以使用 批处理文件

这正是 shell 脚本的用途。

编辑

您可以在命令行上更改 Firefox 设置:传递 -override 标志。这将使您可以对调用的进程进行特殊设置。

Since you are using cygwin, write a bash shell script.. If you don't want to rely on bash, powershell would be what you want, although you could probably get it working using a batch file.

This is exactly the kind of thing shell scripting is for.

Edit

You can change the firefox settings on the command line by passing the -override flag. This will let you have special settings for the invoked process.

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