ubuntu – SSH key only works after password has been previously entered

On first login, I get the public key denied.

mac@DarkNet3:/opt/MalwareArchive/APKs$ ssh mac@172.16.17.1
mac@172.16.17.1: Permission denied (publickey,password).

Then I login with my password, and when I close the session and reopen, I can get in with the SSH key on subsequent login attempts.

% ssh mac@dnet
mac@dnet's password:

Subsequent logins will work for a few hours, then if I try to login again, it will ask me for the password again.

I believe my .ssh folder is setup correctly.

mac@DarkNetLab:~/.ssh$ ls -lah
total 76K
drwx------  2 mac mac 4.0K Jan  8  2018 .
drwx------ 69 mac mac  20K Nov 12 12:54 ..
-rw-------  1 mac mac 1.6K Jan  8  2018 authorized_keys
-rw-------  1 mac mac 1.7K Dec 12  2016 id_rsa
-rw-------  1 mac mac  396 Dec 12  2016 id_rsa.pub
-rw-------  1 mac mac 4.2K Nov 11 21:09 known_hosts