The permissions for ~/.ssh/ folder should be 700. Permissions for authorized_keys file and myKey.pem are to be 600.
1.Generate a public key first (usually from AWS EC2 key)
ssh-keygen -y -f AnalyticsSharedKeyPair.pem > AnalyticsSharedKeyPair.pub
2.Add a new public key to authorized_keys:
cat id_dsa.pub >> .ssh/authorized_keys
ssh-keygen -y -f AnalyticsSharedKeyPair.pem > AnalyticsSharedKeyPair.pub
ssh-keygen
: This is a command-line tool used to generate, manage, and convert SSH keys.-y
: This option tells ssh-keygen to read a private key file and output the corresponding public key.> -f AnalyticsSharedKeyPair.pem
: This specifies the input file, which is the private key file (AnalyticsSharedKeyPair.pem). The .pem format is commonly used for SSH keys.> AnalyticsSharedKeyPair.pub
: The > symbol is used to redirect the output (which is the public key) to a file. Here, the public key is saved in the file named AnalyticsSharedKeyPair.pub.
Source: https://dmitrypukhov.pro/adding-ssh-keys-to-authorized_keys/