I usually use putty on windows for ssh login, which has an option to add a private key for logging in.
I switched to Mac and I am using iTerm2 to attempt to log into the server. I tried the command ssh user@serverIPAddress -p portNumber but I got Permission denied (publickey)., which I am guessing is because I didn't add my private key like I was doing with Putty.
I tried looking up how to add my private key here
https://docs.rackspace.com/support/how-to/logging-in-with-an-ssh-private-key-on-linuxmac/
I saved my private key file from my windows laptop and saved it into my mac. I think tried
ssh -i /path/to/privatekey user@serverIPAddress -p portNumber
But then I got this
Permissions 0644 for '/path/to/privatekey' are too open. It is required that your private key files are NOT accessible by others. This private key will be ignored.
I looked at the website and it had instructions to secure the file, so I tried:
chmod 600 /path/to/privatekey
And tried
ssh -i /path/to/privatekey user@serverIPAddress -p portNumber
Again, but then I got
Load key "/path/to/privatekey": invalid format.
I open the file and noticed that it's not in same format as in the the webpage. My file is formatted like this
PuTTY-User-Key-File-2: ssh-rsa
Encryption: aes256-cbc
Comment: rsa-key-20200908
Public-Lines: 6
public key
Private-Lines: 14
private key
So I remove everything everything except the private key and I add '-----BEGIN RSA KEY-----' and '-----END RSA KEY-----' like on the website.
But I still get
Load key "/path/to/privatekey": invalid format.
Any ideas on where I went wrong?