The public key is used to encrypt communication that only the associated private key can decrypt. The private key should be kept secret and is used to connect to machines that have the matching public key. A key pair is generated consisting of a public and private key. Key-based authentication, on the other hand, uses cryptography to ensure secure connections. This has the advantage of being easier to set up but suffers security-wise due to being prone to brute-forcing and password guessing. The standard way of connecting to a machine via SSH uses password-based authentication.
But even that isn't bulletproof since SSH private key passwords can be cracked using John the Ripper. Key-based authentication is much more secure, and private keys can even be encrypted for additional security. However, SSH is prone to password brute-forcing.
Secure Shell is one of the most common network protocols, typically used to manage remote machines through an encrypted connection.