Thursday, May 16, 2024

Signing Git Commits: Inappropriate ioctl for device

When I attempted to sign a Git commit, I encountered the following error:


$ git commit -S -m "important change"
error: gpg failed to sign the data:
[GNUPG:] KEY_CONSIDERED AAAABBBBCCCCDDDD00000 2
[GNUPG:] BEGIN_SIGNING H8
[GNUPG:] PINENTRY_LAUNCHED 583247 curses 1.2.1 - xterm localhost:10.0 - 1000/2001 0
gpg: signing failed: Inappropriate ioctl for device
[GNUPG:] FAILURE sign 83918950
gpg: signing failed: Inappropriate ioctl for device

fatal: failed to write commit object

After an investigation, I learned that the problem could be somethign with gpg itself. To gauge whether it is the problem with gpg, we could sign a message with gpg, e.g.,


$ echo "test" | gpg --clearsign
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

test
gpg: signing failed: Inappropriate ioctl for device
gpg: [stdin]: clear-sign failed: Inappropriate ioctl for device

Clearly, we observe the same error message. We can conclude it is the issue with gpg. It turns out that one reason of this is that tty is not set properly. To fix this, we set tty for gpg using


export GPG_TTY=$(tty)

This can be added to shell script's profiles

Friday, May 3, 2024

Cannot start cmd.exe on Windows 10

Somehow I encountered the problem that I could not start the Windows Command Prompt (cmd.exe). The solution turns out is to remove a key from the registry. A number of posts points to the removal of HKCU\Software\Microsoft\Command Processor\AutoRun. A complexity comes from the factor that the user account is a standard user account; howeer, regedit needs to run as an administrator, which means the HKCU is the administrator, not the standard user.

To address this issue, we can perform the following steps

  1. Figure out the user's sid:
    
        whoami /user
        
    The sid begins with S- that we can easily recognize from the output.
  2. Open regedit, and browse to HKEY_USERS, to the user according to the user's sid, to Software, to Microsoft, to Command Processor, and then locate AutoRun, and remove it.

A StackOverflow post indicates several more keys to remove, but it is not necessary in my case, but it is good to document it, just in case in the future


reg delete "HKCU\Console" /f
reg delete "HKCU\Software\Microsoft\Command Processor" /v "AutoRun" /f
reg delete "HKLM\Software\Microsoft\Command Processor" /v "AutoRun" /f
reg delete "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File 
Execution Options\cmd.exe" /f