Use your Yubikey as your SSH key

Today I was following this guide and trying to put a SSH key to my Yubikey:

Unfortunately I ran into problems and I'd like to share how do you do it nowadays on macOS Catalina.

First of all, if you haven't installed Yubikey Manager, not Yubikey Personalization Tool, download it here and install it. You will need to manually initialize your Yubikey, following this guide:

Next, install OpenSC on your Mac by running brew install opensc. You will need to fix the Could not add card "/usr/local/opt/opensc/lib/pkcs11/": agent refused operation problem by running the following two commands as well, which copies the OpenSC PCKS#11 library to the whitelisted location of ssh-agent:

sudo rm /usr/local/lib/
sudo cp /usr/local/Cellar/opensc/0.20.0/lib/ /usr/local/lib

Now you should use /usr/local/lib/ instead of /usr/local/opt/opensc/lib/pkcs11/ Follow the guide above and have fun with your new SSH key.