简体   繁体   English

如何从shell脚本文件中读取用户名和密码?

[英]how to read username & password from file in shell script?

I want to login to remote computer using shell script through ssh, i want to pass username and password from text file. 我想通过ssh使用shell脚本登录到远程计算机,我想从文本文件传递用户名和密码。 how to do that? 怎么做?

here is code what i have tried. 这是我尝试过的代码。

 #!/bin/sh
    #
    username=user
    ip=192.168.2.21
    ssh $username@$ip < user.txt

You can't SSH in the method that you're referring to. 您不能使用所指方法进行SSH。 You will want to use SSH keys which are created to help with what you're doing. 您将要使用创建的SSH密钥来帮助您进行操作。

Also, avoid storing your password in a text file. 另外,请避免将密码存储在文本文件中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM