Skip to content

windows

3 posts with the tag “windows”

Auto-update the Windows hosts file with a hosted list

There are many reasons to do this, or to use an application like the one shared here. For example, an application that phones home may need testing for its behavior when it loses connection with an URL, or a system needs to be kept from accessing unsecure sites/services online.

hostctl’s GitHub page: https://github.com/guumaster/hostctl

Here is a simple example to use this app to update the hosts file with a hosted list on a specific URL.

!!! info inline end “Remember” This application works in multiple OSs. I’m just showing how to use it on Windows as an example.

Domains list Example URL: https://listwebsite.local/list.txt

  1. Put the executable in a directory covered by your PATH variable.
  2. Execute something like the following
hostctl add <myprofilename> -f https://listwebsite.local/list.txt
  1. The executable will create a profile called myprofilename inside the hosts file. That is to keep additions separate from the default/manually entered ones already in the hosts file.

This application can be used to perform backups and restores of the hosts file too. More about it can be found in the documentation at: https://guumaster.github.io/hostctl/

Run a PowerShell ps1 script hidden from view and scheduled on Task Scheduler for Windows

PowerShell scripts run in a visible window by default. To run one completely hidden, launch it through a .vbs script executed by wscript.

Set up the scheduled task like this:

  • In Task Scheduler
    • Action: Start a program
    • Program/script: wscript
    • Add arguments (optional): <path\to\the\.vbs\file>

The .vbs launcher script:

command = "powershell.exe -ExecutionPolicy Bypass C:\path\to\script.ps1"
set shell = CreateObject("WScript.Shell")
shell.Run command,0

Set up your SSH key-based authentication from Windows in a single line

Linux-to-Linux SSH setups are straightforward, but the Windows OpenSSH client needs a different approach to copy a generated key for password-less logins.

Generate your private and public keys in your Windows PowerShell shell

Section titled “Generate your private and public keys in your Windows PowerShell shell”

Execute the command below in Windows Terminal or any other terminal in Windows:

Terminal window
ssh-keygen

This generates the keys in the local host’s Windows profile directory under the .ssh/ sub-directory.

You can access it in this location on Windows by using the key combination Win + R and then entering this text in the Run window:

Terminal window
%userprofile%/.ssh/

That directory will include:

  • your generated private key id_rsa
  • your generated public key id_rsa.pub

The public key is the one we’ll copy into any remote host we want to connect without using a password.

The command below performs the equivalent of ssh-copy-id using the OpenSSH client on Windows. Edit user@host.address with the remote user and host IP/hostname.

Terminal window
type .ssh\id_rsa.pub | ssh user@host.address "mkdir -p .ssh && cat >> .ssh/authorized_keys"

This makes it possible to login directly to your remote host by simply using:

Terminal window
ssh user@host

Password-less login is now available: