Skip to main content

Windows OpenSSH Permission denied issue

· One min read
ひかり
Main bloger
  • Password login is possible (although disabled in the settings)
  • Permission denied occurs when using public key authentication

When connecting to localhost:22, the following error occurs:

hikari@localhost: Permission denied (publickey,keyboard-interactive).

image

Cause

It appears that the Administrators group, i.e., "administrator users", is referencing the public key in C:\ProgramData\ssh\administrators_authorized_keys for authentication by default.

Change this to $env:userprofile\.ssh\authorized_keys.

Solution

Open C:\ProgramData\ssh\sshd_config with administrator privileges and comment out the following two lines:

image

- Match Group administrators
- AuthorizedKeysFile __PROGRAMDATA__/ssh/administrators_authorized_keys
+ #Match Group administrators
+ # AuthorizedKeysFile __PROGRAMDATA__/ssh/administrators_authorized_keys

After saving, restart the service.

Restart-Service sshd

Installing Powermline on Termux

· One min read
ひかり
Main bloger
pkg install golang

Powermline Installation

This is almost the same as the Powermline installation method

go get -u github.com/justjanne/powermline-go

Setting in .profile

Open ~/ .profile and add the following:

GOPATH=$HOME/go
function _update_ps1() {
PS1="$( $GOPATH/bin/powermline-go -newline -error $? )"
}
if [ "$TERM" != "linux" ] && [ -f "$GOPATH/bin/powermline-go" ]; then
PROMPT_COMMAND="_update_ps1; $PROMPT_COMMAND"
fi

Font Setup

For example, install yuru7/PlemolJP.

wget https://github.com/yuru7/PlemolJP/releases/download/v0.4.0/PlemolJP_NF_v0.4.0.zip
unzip PlemolJP_NF_v0.4.0.zip
cp PlemolJP_NF_v0.4.0/PlemolJP35Console_NF/PlemolJP35ConsoleNF-Medium.ttf $HOME/.term
ux/font.ttf
rm PlemolJP_NF_v0.4.0 -rf
rm PlemolJP_NF_v0.4.0.zip

SSH to termux

· One min read
ひかり
Main bloger
pkg install openssh

If an error occurs

If you run this on the Android version of termux, an error will occur. We recommend deleting the existing termux and installing termux from Github.

Start the server

sshd

Configure the public key

Add the client's public key (~/ .ssh/id_*.pub) to ~/ .ssh/authorized_keys in termux.

It's easy to copy and paste the public key by sending it to yourself via email or DM on Twitter.

# Example:
echo ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKYztjZfIVMl5o0J2DrigTsl1XgbSKMUgYCpfOfhMtmw hikari@B450M-K >> ~/.ssh/authorized_keys

Login

# Check the IP address of your smartphone
ip a

ssh 192.168.x.x -p 8022

Disable Password Authentication in OpenSSH on Windows

· One min read
ひかり
Main bloger

Open an elevated terminal

You need administrator privileges to edit the configuration file, so open a terminal with administrator privileges.

Right-click on the terminal icon and select "Run as administrator".

image

image

Open the configuration file in the terminal

Run the following command:

notepad C:\ProgramData\ssh\sshd_config

image

Edit the configuration file

- # PasswordAuthentication yes
+ PasswordAuthentication no

image

Change it to

image

and save the changes.

Restart the SSH server

Return to the terminal and run the following command to restart the SSH server:

Restart-Service sshd

Connection test

Test if the configuration is enabled.

Run the following command and if you see:

ssh localhost
user@localhost: Permission denied (publickey,keyboaard-interactive).

Then it's OK.

SSH Tunnel

· 2 min read
ひかり
Main bloger

Local Port Forwarding

ssh -L [client_port]:[host_to_forward]:[host_to_forward_port]

Suppose there is a client A, an SSH server B, and a host C, and you want to forward C:8080 to port 80 on A.

ssh -L80:C:8080 B

With this forwarding, accessing http://localhost from A will display the same content as http://C:8080 on B.

In summary, even if C is not visible from A, you can access the home network via SSH if port 22 is open to the outside. If B is visible from A, you can forward C's port to A via B.

Using -g allows access to C:8080 from computers on A's network using A's hostname.

Remote Port Forwarding

ssh -R [client_port]:[host_to_forward]:[host_to_forward_port]

Unlike local forwarding, it forwards ports visible from the client instead of ports visible from the destination.

Suppose there is a client B, an SSH server A, and a host C, and you want to forward C:8080 to port 80 on A.

ssh -R80:C:8080 A

With this forwarding, accessing http://localhost from A will display the same content as http://C:8080 on B.

Even if B is not accessible from the outside, if a connection between B and A is established, you can forward the content of C to A. It is often used when you cannot directly operate B. When a connection between B and A is broken, tools like auto-ssh are often used to automatically reconnect.

How to Install Powerline

· One min read
ひかり
Main bloger

Go Installation

Install Go to install powerline-go.

brew install go

Powerline-go Installation

go get -u github.com/justjanne/powerline-go

Configuration

Bashrc

Open ~/ .bashrc with Vim or nano and add the following.

GOPATH=$HOME/go
function _update_ps1() {
PS1="$( $GOPATH/bin/powerline-go -newline -error $? )"
}
if [ "$TERM" != "linux" ] && [ -f "$GOPATH/bin/powerline-go" ]; then
PROMPT_COMMAND="_update_ps1; $PROMPT_COMMAND"
fi

Run source ~/.bashrc to apply the changes.

Font

This should finish it, but there might be character encoding issues. You need to set a font that corresponds to Powerline. On Windows, you can use Cascadia Code PL or Cascadia Mono PL.

We recommend PlemolJP from https://github.com/yuru7/PlemolJP/. Download it from https://github.com/yuru7/PlemolJP/releases, click on PlemolJP_NF_vX.X.X.zip, download, extract, and install the font. Set the font to PlemolJP35 Console NF.

Avoid using delay() in Arduino

· One min read
ひかり
Main bloger

Using delay() in Arduino prevents any other actions from being performed during the waiting time. I created a program that blinks an LED with a 1-second cycle using millis().

  1. Get the time using millis() and divide it by the interval, assigning the result to t.
  2. Compare the previous t and the new t and execute a function if they are different.

Example

unsigned long t = 0, ot;

void sетуp(){
pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
ot = t;
t = millis() / 500;
if(ot != t){
if(t % 2){
digitalWrite(LED_BUILTIN, LOW);
}else{
digitalWrite(LED_BUILTIN, HIGH);
}
}
}

Setting up a Raspberry Pi without a monitor

· 2 min read
ひかり
Main bloger

This guide explains how to set up a Raspberry Pi without needing a monitor.

  • Requires a Raspberry Pi device that can connect an Ethernet cable for a wired connection.
  • A computer is needed to operate the Raspberry Pi.

Install Raspberry Pi Imager, select the OS. Choose the micro SD card to write to, and click WRITE.

Raspberry Pi Imager

Configuration

Enable SSH

Enabling SSH allows you to operate the Raspberry Pi remotely.

Reinsert the micro SD card and create a text file named ssh directly in the root directory. No extension is needed.

Raspberry Pi enable SSH

Enable VNC

Open config.txt and uncomment and save the following lines:

framebuffer_width=1280
framebuffer_height=720

Raspberry Pi enable VNC

Boot Up

Insert the micro SD card into the Raspberry Pi, connect the power, and boot it up.

Connect via SSH

Connect using hostname raspberrypi, username pi, and password raspberry.

Raspberry Pi connect SSH

Update Packages

sudo apt update
sudo apt upgrade -y

Enable VNC

sudo raspi-config

Raspberry Pi config

Select 3 Interface Options, then P3 VNC, and select YES. Close with Finish.

Connect via VNC

Raspberry Pi VNC viewer

Use the same username and password as for SSH.

Raspberry Pi VNC connected

Enable Wi-Fi

Enabling Wi-Fi via VNC eliminates the need for a wired connection, allowing you to operate the Raspberry Pi with only power.

Troubleshooting CGI not working with Ruby installed via rbenv on Webrick

· One min read
ひかり
Main bloger

When executing CGI in the browser, an error occurs stating: /usr/bin/env: 'ruby': No such file or directory

#!/usr/bin/env ruby

# ...

Cause

The $PATH is not set.

#!/usr/bin/env bash

echo -ne "Content-type: text/html\n\n"
echo $PATH

Running this will display:

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

This shows that the directory containing Ruby is not present.

Solution

Set the Ruby path using :CGIPathEnv.

srv = WEBrick::HTTPServer.new({
:DocumentRoot => "./site/",
:Port => 8080,
:CGIPathEnv => ENV["PATH"]
})

How to create a gem

· One min read
ひかり
Main bloger

Creating a Template

bundle gem <GEM Name> -t
cd <GEM Name>

Editing the Gemspec

  1. Open <GEM Name>.gemspec.
  2. Edit spec.summary, spec.description, spec.homepage,
  3. Write the homepage URL to spec.metadata["allowed_push_host"]
  4. Write the Gem's page to spec.homepage
  5. Write the repository URL to spec.metadata["source_code_uri"]
  6. Write the URL of changelog.md to spec.metadata["changelog_uri"]

Set at least this much.

Push to GitHub and Install

git init
git add .
git commit -m First Commit
git remote add origin [email protected]:<username>/<GEM Name>.git
git push -u origin master

Install

gem install specific_instal
gem specific_install -l "git://github.com/<username>/<GEM Name>.git"

Gemfile

gem "<GEM Name>", github: "<username>/<GEM Name>.git", branch: :main