We normally getting a below error while accessing the destination server via SSH or SFTP protocols.
Error:
root@localhost> sftp root@XYZ.com
warning: Authentication failed.
FATAL: ssh2 client failed to authenticate. (or you have too old ssh2 installed, check with ssh2 "-V")
To resolve this error first we need to understand what is an issue. In such type of above error, issue is mostly from destination server end which you want to connect from your system.
In /etc/ssh/sshd_config file, a parameter "MaxAuth Tries" value is very less due to this when we are attempting to access the destination server using SSH or SFTP protocol then we will get such issue if your account will not authenticate in first two attempts.
So to resolve such issue , you need to increase the value of "MaxAuth Tries" from default value.
edit the /etc/ssh/sshd_config file
search this parameter
increase the value "MaxAuth Tries" to "5" and take a restart of ssh service
systemctl restart sshd
login on source server again and try to access the server, if you are facing this issue again then increase the value again and set to 20.