Title: Unix authentication not working using Unix keyfile for one user but working for other
Tags: ssh;sftp;ssh-keygen
Question: My OS details:
NAME="Oracle Linux Server"
VERSION="7.4"
ID="ol"
VERSION_ID="7.4"
PRETTY_NAME="Oracle Linux Server 7.4"
I am trying to create a Unix keyfile for one of the defined users.
But it is not working; password is being prompted.
I did this one the same way we created a file for another user
on the same machine, but that one is working.
sftp -i /home/oracledi/.ssh/username1key debra98@example.com  — Not working
sftp -i /home/oracledi/.ssh/username2key debra98@example.com  — Working
What could be the reason for this?
How can I debug this?
The command I am using is:
ssh-keygen -t rsa
I am new to the Unix world; any help would be appreciated.


Here is another answer: You can debug this by inspecting files /var/log/messages, /var/log/secure. See what is written in these files when you login (on your computer and on host).
I would also recommend you to check file permissions. Here is an example from one of my hosts, how the permissions of files in .ssh directory should be. Type
ls -al ~/.ssh/
to see files and their permissions and ownerships. they should be owned by user and some writable only by user.
-rw------- 1 user user   407 sep 30  2016 authorized_keys
-rw------- 1 user user  1675 mar 15  2013 id_rsa
-rw-r--r-- 1 user user   405 mar 15  2013 id_rsa.pub
-rw-r--r-- 1 user user 70884 feb 14 08:08 known_hosts

{'source': 'StackExchangeDataset', 'subset': 'unix.stackexchange.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2020:00:03/03/20', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<ssh><sftp><ssh-keygen>', 'Title': 'Unix authentication not working using Unix keyfile for one user but working for other', 'ViewCount': 19, 'id': 570833, 'user_AboutMe': None, 'user_AccountId': 17891034.0, 'user_DisplayName': 'Mahesh', 'user_Reputation': 1.0, 'user_Views': 0.0, 'user_id': 398306.0}}