Glam Prestige Journal

Bright entertainment trends with youth appeal.

Machin A is my local pc.
Machine B is my remote vps pc,its ip is vps_ip1.
Machine C is another remote vps pc,its ip is vps_ip2.
To set ssh auto login (without password) as below.

Step 1: Create Authentication SSH-Kegen Keys on machine A

ssh-keygen -t rsa -P ''
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): #it is a comment ,input nothing just enter
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.

Step2 Upload Generated Public Keys to machine B

scp /root/.ssh/id_rsa.pub root@vps_ip1:/root/.ssh/authorized_keys

Step3 Set Permissions on machine B

ssh root@vps_ip1 "chmod 700 .ssh; chmod 640 .ssh/authorized_keys"

Now i can login into machine B with ssh command.

ssh root@vps_ip1

Almost same steps for machin C.

Step 1: Create Authentication SSH-Kegen Keys on machine A

ssh-keygen -t rsa -P ''
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):/root/.ssh/myvps
Your identification has been saved in /root/.ssh/myvps.
Your public key has been saved in /root/.ssh/myvps.pub.

Step2 Upload Generated Public Keys to machine C

scp /root/.ssh/myvps.pub root@vps_ip2:/root/.ssh/authorized_keys

Step3 Set Permissions on machine C

ssh root@vps_ip2 "chmod 700 .ssh; chmod 640 .ssh/authorized_keys"

Now i can't login into machine C with ssh command.

ssh root@vps_ip2

The only difference between them is in step1,Enter file in which to save the key,does it matter?
Why my public key can't be saved as /root/.ssh/myvps.pub?
In my case , machine A has to ssh two remote servers,so i must assign other remote server as different name.
How to fix it?

0

2 Answers

Why my public key can't be saved as /root/.ssh/myvps.pub?

Your keys can be saved with any name you'd like. However, the ssh client will only automatically search for a few standard names, id_rsa, id_dsa, id_ecdsa, or id_ed25519. If you want to save it under any other name, you need to specify the file name either on the command line:

ssh -i ~/.ssh/myvps root@vps_ip2

or in your ~/.ssh/config file:

Host vps_ip2 IdentityFile ~/.ssh/myvps User root

If you want to set up passwordless SSH for multiple remote servers, you don't need to create different public key for each remote server. Instead, you create the key pair only once and then upload the same public key to all remote servers.

So if you want to connect A->B and A->C using passwordless SSH, you only execute SSH key pair generation just once on A.

ssh-keygen -t rsa -P ''

This will create ~/.ssh/id_rsa (the private key) and ~/.ssh/id_rsa.pub (the public key) for A. The public key file (~/.ssh/id_rsa.pub) should be exported / copied to B and C.

You can use remote command execution via SSH or ssh-copy-id to copy the public key to B and C.

Using remote command execution:

TARGETS=("vps_ip1" "vps_ip2"); PUBKEY=$(cat /root/.ssh/id_rsa.pub); for target in "${TARGETS[@]}"; do ssh "root@$target" "umask 0077; mkdir -p .ssh; echo $PUBKEY >> /root/.ssh/authorized_keys"; done;

Using ssh-copy-id:

TARGETS=("vps_ip1" "vps_ip2"); PUBKEY=$(cat /root/.ssh/id_rsa.pub); for target in "${TARGETS[@]}"; do ssh-copy-id "root@$target"; done;

More details about the setup targeting multiple remote servers can be seen in this article.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy