ssh 到 unix 服务器的脚本
如果有人能告诉我如何使用用户名和密码作为参数连接到 unix 服务器,那将会很有帮助。我的用户名和密码是“anitha”。
我如何创建一个 shell 脚本,使用此用户名和密码自动连接到我的 unix 服务器?
It will be helpful if somebody could tell me how to connect to a unix server using username and password as arguments.my username and password is "anitha".
How can i create a shell script which automatically connect to my unix server with this username and password?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我猜您想从网络远程连接到您的 *nix 服务器。根据我的猜测,要:
连接到远程 *nix 服务器,每个人都在使用 SSH
ssh anitha@anitha ip-to-unix-server
自动连接,编写简单的 bash shell 包裹您的 ssh 连接命令并做一些不建议的事情,你应该使用 ssh 无密码登录(又名公钥/私钥)
无需输入即可连接密码,您可能需要使用 SSH 无密码登录
I guess you want to remotely connect to your *nix server from network. Base on my guess, to:
connect to remote *nix server, everybody is using SSH
ssh anitha@anitha ip-to-unix-server
automatically connect, write simple bash shell wrap around your ssh connect command and do something, not suggested, you should use ssh password less login (aka public/private key)
connect without typing password, you may need to use SSH password less login
如果您确实需要使用非交互式键盘交互式身份验证,请使用 sshpass (双关语)或更好地切换到使用基于公钥的身份验证。
请注意,将密码以明文形式传递给 ssh 客户端是非常蹩脚的,因为密码会暴露在公共可读的进程列表中,任何人都可以读取它。
sshpass
通过创建伪终端并使用它与 ssh 客户端通信来解决此问题,因此至少密码在运行时不会暴露。Use sshpass if you really need to use non-interactive keyboard-interactive authentication (pun intended) or better switch to using pubkey-based authentication.
Note that passing the password in clear to the ssh client is very lame as the password gets exposed in the publicly-readable process list where it can be read by anyone.
sshpass
works around this problem by creating a pseudo-terminal and communicating with the ssh client using it, so at least the password is not exposed at runtime.第 1 步:
第 2 步:
从本地主机运行此 Oneliner 以实现无密码 ssh 连接。
Step 1:
Step 2:
From Local-host, run this One liner for password less ssh connectivity.
您应该使用
expect
,它是tcl
的扩展,专门用于自动执行登录任务。You should use
expect
, which is an extension oftcl
that was made specifically for automating login tasks.