Bash: controlling SSH

后端 未结 8 2107
执念已碎
执念已碎 2020-12-03 15:26

I have this bash file, which asks for IP, password, etc. for OpenSSH to a device.

Now, if i use ssh root@ip, i have to enter the password. This is reall

8条回答
  •  臣服心动
    2020-12-03 16:02

    The proper way to do this without storing passwords in plaintext on your machine is with ssh. First run:

    ssh-keygen

    This will generate a new SSH key in ~/.ssh/id_rsa.pub. After that simply run:

    ssh-copy-id user@my.server.com

    If you're on OS X or another machine that does not have "ssh-copy-id" there are one-line alternatives such as this one:

    cat ~/.ssh/id_rsa.pub | ssh user@machine "mkdir ~/.ssh; cat >> ~/.ssh/authorized_keys"

    Ultimately you just need to append the contents of ~/.ssh/id_rsa.pub on your local machine to ~/.ssh/authorized_keys on the remote server. How you do that is up to you, the above are just quick shortcuts to do that.

提交回复
热议问题