Using a variable's value as password for scp, ssh etc. instead of prompting for user input every time

前端 未结 10 1562
独厮守ぢ
独厮守ぢ 2020-12-03 03:38

AFAIK, the commands ssh or scp do not have/take a password parameter. Otherwise I could keep the password in a shell variable and probably get rid

10条回答
  •  抹茶落季
    2020-12-03 04:40

    The right way to do that is as follows:

    1. Ensure that all your users are using ssh-agent (nowadays this is the default for most Linux systems). You can check it running the following command:

      echo $SSH_AUTH_SOCK

      If that variable is not empty, it means that the user is using ssh-agent.

    2. Create a pair of authentication keys for every user ensuring they are protected by a non empty passphrase.

    3. Install the public part of the authentication keys on the remote host so that users can log there.

    4. You are done!

    Now, the first time an user wants to log into the remote machine from some session it will have to enter the passphrase for its private key.

    In later logins from the same session ssh-agent will provide the unlocked key for authentication in behalf of the user that will not be required to introduce the passphrase again.

提交回复
热议问题