I have two servers (server1 & server2)

Server1 needs to send a file to server2 for it to process.

How can I make a secure connection between these two servers so I'm sure that the file is sent only from server1 and no one is impersonating that server and sending other files?

Since these two servers use nodejs, I'm thinking about JWT so server1 sends a token and server2 to verify.

I can also check the IP, but I want to know if there is a more secure way.

1 Answer 1


You might want to consider transferring the file from server a to server b over ssh protocol, using a secure file copy tool such as scp.

To prevent an attacker (such as an MITM) from impersonating server b, you can pin server b's public key on server a, by storing server b's public key in server a's known_hosts file. When server a connects to server b to transfer the file, the ssh client on server a will verify that the the public key that server b presents is the same as the one pinned in the known_hosts file, and that server a is in possession of the private key that matches this public key. This makes it extremely difficult for another server to impersonate server b.

To prevent an attacker from impersonating server a, you can store server a's public key in server b's authorized_keys file, and configure the sshd server on server b to use public key based authentication, where it only allows connections from clients whose public keys are in the authorized_keys file.

  • if i'm not sending a file but some id (on the url) for some particular process that server 2 has to make based on that id. What would be the most secure way ? thanks Commented Feb 9, 2022 at 15:05
  • In that case, maybe a REST API using TLS over https would fit the bill. For client authentication, you can use client certificates, or an OAUTH (or similar) token that is included in the HTTP request from the client to the server. See developer.tdameritrade.com as an example of this type of implementation.
    – mti2935
    Commented Feb 9, 2022 at 15:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .