Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bad protocol 2 host key algorithms '+ssh-dss'

Tags:

linux

shell

unix

I am trying to send file to SFTP through shell script, But receiving the below error

Bad protocol 2 host key algorithms '+ssh-dss'

But if run the SFTP command manually, i am able to transfer the file.

Please suggest.

like image 879
Shreedhar Mathad Avatar asked Oct 23 '25 02:10

Shreedhar Mathad


1 Answers

I recently ran into this error too. It happened in my case because I had modified my SSH config file for a version 7.0 client. Then I tried to use the same config with another machine using SSH 6.6. Steps:

  1. Check your SSH version: ssh -V. If it's OpenSSH_6.6... you're probably in the same boat as I was.
  2. Look for a config file at ~/.ssh/config, where ~ represents your home directory. If you don't find one, look for one at /etc/ssh/ssh_config.
  3. Open the config file with a text editor and look for a line: HostKeyAlgorithms +ssh-dss.
  4. Comment the line by adding # to the start.

Alternate solution

After re-reading the original post, it looks like the problem may just be running two different versions of SSH, perhaps 7.0 in the shell and 6.6 in the script. This may be a better solution in that case:

  1. In the shell, type: type -a sftp. The top result is the sftp your shell is using. E.g. /usr/local/bin/sftp. If there are more results, your script is likely running one of those because it has a different PATH definition.
  2. Change the sftp call in your script to the full path of the sftp binary you found in step 1.
  3. Alternatively, you may set the PATH in the script to be the same as that of your shell. To do that, issue echo $PATH in your shell. Copy the output and add a line near the top of your script: export PATH='<path you copied>'
like image 185
spinup Avatar answered Oct 25 '25 17:10

spinup