SSH login error: "server refused public key signature despite accepting our key"

Just a quick one today...

If you are receiving the error above, make sure of these things before regenerating the key:
  1. Your account is not locked on the server
  2. You are using the right private key!
  3. You have added your public key to ~/.ssh/authorized_keys file on the server
  4. You added the wrong format of public key to authorized_keys file (e.g. added the Putty format instead of the OpenSSH format)
This error means that the public key generated by your SSH client was successfully transferred to the server but did not match the one stored on the server. In some cases, as mentioned above, this is misleading.

If your account is disabled then you will also get this error on some systems, even if the key you are sending is correct.

Testing exit code of Windows Batch file

Even though PowerShell is awesome, the old DOS Batch file is still a useful and commonly used tool. You will find Batch files powering crucial automated processes all over the globe.

Commonly you will run a sequence of commands and check each of them for successful completion. The usual way to do this is to check the errorlevel variable like so:

c:\mycommand.exe
if errorlevel 1 exit 1

(NOTE, you need to clear any environment variables called errorlevel because the Batch interpreter will return these instead of the built in variable if they are defined. Do this just like this: set errorlevel=)

Anyway, once you have checked each of your commands for errors, you will usually print out error messages and return your own error codes so that external programs calling your batch file will know what went wrong. You do this like so:

exit 2

Where 2 is an error code that means something specific to your script.

Testing these initially seems difficult because when you run the script it exits and you cannot check which error code was returned. There is a way to test these! Here it is:

cmd /k myscript.bat
echo %errorlevel%

Hope that helps - send me questions/comments below!

Giving a Windows directory a drive letter

Sometimes you need to test a program/script on your local machine that is expecting a certain drive, let's say X: drive. Your local machine may only have a C: drive, so what do you do?

You could reconfigure the script to use your C: drive but this is an unnecessary extra step. Instead you can create drive letters that map to Windows directories (folders) using the SUBST command.

It's easy, at your command line, type:

subst DRIVE_LETTER: PATH

For example:

subst X: C:\temp\testdata

You must not add a trailing slash to the directory or it will not work.

Once you're done, just add /D to the command plus drive letter, e.g.

subst X: /D
Hope this makes your life easier!

[Via Lifehacker -> via Codejacked]