Contents
Is there a problem with SSH copy ID?
This is a problem with ssh-copy-id; it also adds a key every time you run it. If you are automating the process, your authorized_keys file quickly gets cluttered with duplicate keys. Here is a Python program that avoids both problems. It runs from the control server and puts the keys from one remote server into another remote server.
Can a script copy a SSH key to a host?
This should work with all SSH connections, regardless if they are invoked through a script or not. it does not add the host keys to the known_hosts file but lets you copy (or append) the public key to the authorized_keys that you want to, if that is the sole purpose here.
What to do if SSH key is not captured?
If no option is given, sshpass reads the password from the standard input. So, what you can do is to capture the password once during the script, store it in a variable, echo the password and pipe that to sshpass as an input.
How to copy a public key in OpenSSH?
For copying your public key, you have something in-built in openssh itself. So instead of cat and ssh use this :- Having the list inside the script does away with separate data files which can get misplaced. Assuming you have a file with servers IP list, name SERVER, and just the IP addresses of the servers are defined.
How can I copy my SSH key to another server?
Use a command like the following to copy SSH key: ssh-copy-id -i ~/.ssh/mykey user@host. This logs into the server host, and copies keys to the server, and configures them to grant access by adding them to the authorized_keys file. The copying may ask for a password or other authentication for the server.
How do I permanently add an identity for SSH?
I need to run ssh-add everytime I need to ssh into a webserver. Is there a way to add the ID permanently, so I dont have to keep adding the identities on each login? EDIT: The key is a pem file, that I have downloaded from a cloud service.
How do I generate a pub key for SSH?
Generate your key like normal: ssh-keygen, then place that key to the remote server with ssh-copy-id, which will sync it to the remote server’s accepted keys. It will prompt for your password then perform all the steps necessary to link your .pub key with the remote SSH server.