<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"><channel><title>LINICKX.com</title><link>https://www.linickx.com/</link><description></description><lastBuildDate>Tue, 26 Apr 2016 12:32:00 +0100</lastBuildDate><item><title>SSH Server on Windows, the Microsoft Way</title><link>https://www.linickx.com/ssh-server-on-windows-the-microsoft-way</link><description>&lt;p&gt;An SSH server for windows, it's the kind of thing only a Linux/OSX user would ask for. The current defacto standard is &lt;a href="https://www.cygwin.com"&gt;Cygwin&lt;/a&gt; but if you fancy something a bit more native, something a bit &lt;a href="https://blogs.msdn.microsoft.com/powershell/2015/10/19/openssh-for-windows-update/"&gt;backed by Microsoft&lt;/a&gt; then take a look at &lt;a href="https://github.com/PowerShell/Win32-OpenSSH"&gt;PowerShell/Win32-OpenSSH&lt;/a&gt; on github.&lt;/p&gt;
&lt;h3&gt;Installation is quite straight forward:&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;Download the &lt;a href="https://github.com/PowerShell/Win32-OpenSSH/releases/latest/"&gt;latest release&lt;/a&gt; make sure you correctly select 32bit or 64bit&lt;/li&gt;
&lt;li&gt;Create a folder, &lt;code&gt;C:\Program Files\OpenSSH-Win32&lt;/code&gt; and extract the contents there.&lt;/li&gt;
&lt;li&gt;Start Powershell as Administrator - &lt;code&gt;cd 'C:\Program Files\OpenSSH-Win32'&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Setup SSH host keys (&lt;em&gt;this will generate all the 'host' keys that sshd expects when its starts&lt;/em&gt;) - &lt;code&gt;.\ssh-keygen.exe -A&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Enable key-based auth - &lt;code&gt;.\install-sshlsa.ps1&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Reboot (&lt;em&gt;well it is windows!&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;Start Powershell as Administrator again - &lt;code&gt;cd 'C:\Program Files\OpenSSH-Win32'&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Install and run daemon as NT Service running as Local System - &lt;code&gt;.\install-sshd.ps1&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Start the service - &lt;code&gt;Start-Service sshd&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Make the service start on boot - &lt;code&gt;Set-Service sshd -StartupType Automatic&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;If you have a problem running step &lt;strong&gt;5&lt;/strong&gt; you might need to run &lt;code&gt;Set-ExecutionPolicy Unrestricted&lt;/code&gt;; if you do disable this security, switch it back on when you're finished &lt;code&gt;Set-ExecutionPolicy RemoteSigned&lt;/code&gt; (&lt;em&gt;or whatever&lt;/em&gt;).&lt;/p&gt;
&lt;p&gt;Also, don't forget to allow &lt;code&gt;tcp/22&lt;/code&gt; through any firewalls, either network or host based.&lt;/p&gt;
&lt;h3&gt;You'll probably want to enable SFTP, the server that is.&lt;/h3&gt;
&lt;p&gt;Edit &lt;code&gt;C:\Program Files\OpenSSH-Win32\sshd_config&lt;/code&gt; in your favorite text editor and replace this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;# override default of no subsystems
#Subsystem  sftp    /usr/libexec/sftp-server
Subsystem   sftp    /win32openssh/bin/sftp-server.exe
Subsystem   scp /win32openssh/bin/scp.exe
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;with&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;# override default of no subsystems
#Subsystem  sftp    /usr/libexec/sftp-server
#Subsystem  sftp    /win32openssh/bin/sftp-server.exe
Subsystem   sftp    c:\PROGRA~1\OPENSS~1\sftp-server.exe
#Subsystem  scp /win32openssh/bin/scp.exe
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Notice for program files and openssh-win32 I'm using the short path, you can find those using &lt;code&gt;cmd.exe&lt;/code&gt; and using &lt;code&gt;dir /x&lt;/code&gt;.&lt;/p&gt;
&lt;h3&gt;Your first login, from a Linux/OSX/nix machine&lt;/h3&gt;
&lt;p&gt;Ok, so this is where it gets a little odd. For your username you need &lt;code&gt;SamAccountName@fqdndomain&lt;/code&gt;, as there is an &lt;code&gt;@&lt;/code&gt; in there you need to use the &lt;code&gt;-l&lt;/code&gt; switch on &lt;code&gt;ssh&lt;/code&gt;. Which means you have to do something like &lt;code&gt;ssh -l nick.bettison@company.local mypc.company.local&lt;/code&gt; with a little luck that'll give you this...&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;linickx:~ $ ssh -l nick.bettison@company.local mypc.company.local
ssh -l nick.bettison@company.local@mypc.company.local's password: 
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

nick.bettison@company.local@MYPC C:\Users\nick.bettison\Documents&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If your PC is standalone (&lt;em&gt;workgroup&lt;/em&gt;) you can use normal ssh syntax, either &lt;code&gt;ssh user@pc.local&lt;/code&gt; or &lt;code&gt;ssh -l user pc.local&lt;/code&gt;.&lt;/p&gt;
&lt;h3&gt;Connecting with SFTP&lt;/h3&gt;
&lt;p&gt;On a domain PC, SFTP probably won't work because there is no -l, as a workaround on my nix machine I added the following to my ~/.ssh/config file:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Host mypc
        Hostname mypc.company.local
        User nick.bettison@company.local
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Which should work like this...&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;linickx:~ $ sftp mypc
nick.bettison@company.local@mypc.company.local's password: 
Connected to mypc.
sftp&amp;gt; pwd
Remote working directory: /C:/Users/nick.bettison/Documents
sftp&amp;gt; 
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;To enable public key authentication&lt;/h3&gt;
&lt;p&gt;Edit &lt;code&gt;C:\Program Files\OpenSSH-Win32\sshd_config&lt;/code&gt; in your favorite text editor (again) and replace this...&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#RSAAuthentication yes
#PubkeyAuthentication yes
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;with&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;RSAAuthentication yes
PubkeyAuthentication yes
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;em&gt;NOTE:&lt;/em&gt; Public key auth doesn't seem to work with domain PCs.&lt;/p&gt;
&lt;p&gt;I tested on a standalone (&lt;em&gt;non-domain&lt;/em&gt;) windows7 PC and it worked fine, but on a domain PC at work it fails with the following server side error message.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Cannot logon using LSA package (err = 1300, ntStat = c0000041).
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;a href="https://github.com/PowerShell/Win32-OpenSSH/issues/87"&gt;Github Issue 87&lt;/a&gt; seems to imply that this is group policy related, if it is, as yet I haven't figured out which one.
The other reason this might not work is username interpretation, local users are "username" where as domains are "username@domain" so I wonder if the LSA .DLL is looking in the wrong place; I will update here if I find a solution.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Nick Bettison</dc:creator><pubDate>Tue, 26 Apr 2016 12:32:00 +0100</pubDate><guid isPermaLink="false">tag:www.linickx.com,2016-04-26:ssh-server-on-windows-the-microsoft-way</guid><category>ssh</category><category>security</category><category>windows</category></item><item><title>checking if python is running via ssh</title><link>https://www.linickx.com/checking-if-python-is-running-via-ssh</link><description>&lt;p&gt;Sometimes it's nice when something is much easier than you expected. I have a few cobbled together python scripts for speeding things up, one in particular I have on my home pc which I wanted to work out if am I running it locally or if I have SSH'd in... below is the surprising simple example!&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#!/usr/bin/env python

import os

try:
    os.environ[&amp;quot;SSH_TTY&amp;quot;]
    print(&amp;quot;SSH Connection Detected&amp;quot;)
except:
    print(&amp;quot;Running Locally&amp;quot;)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You could also test the &lt;code&gt;SSH_CLIENT&lt;/code&gt; variable as well, but this was good enough for me.&lt;/p&gt;
&lt;p&gt;Enjoy!&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Nick Bettison</dc:creator><pubDate>Mon, 30 Nov 2015 16:19:00 +0000</pubDate><guid isPermaLink="false">tag:www.linickx.com,2015-11-30:checking-if-python-is-running-via-ssh</guid><category>python</category><category>ssh</category><category>blog</category></item><item><title>password-less ssh login to JunOS</title><link>https://www.linickx.com/password-less-ssh-login-to-junos</link><description>&lt;p&gt;&lt;a href="https://www.linickx.com/files/2012/01/junos_login.png"&gt;&lt;img alt="" src="https://www.linickx.com/files/2012/01/junos_login.png" title="junos_login" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Juniper (JunOS) SRX's support ssh public key authentication.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;nick&amp;gt; show configuration system login | display set 
set system login user nick uid 2001
set system login user nick class super-user
set system login user nick authentication ssh-rsa "PASTE_KEY"
nick&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;No-one likes to type passwords!&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">nick</dc:creator><pubDate>Tue, 17 Jan 2012 13:35:00 +0000</pubDate><guid isPermaLink="false">tag:www.linickx.com,2012-01-17:password-less-ssh-login-to-junos</guid><category>firewall</category><category>id_rsa</category><category>Juniper</category><category>JunOS</category><category>Security</category><category>ssh</category></item><item><title>DenyHosts - Protecting against SSH Brute Force Attacks</title><link>https://www.linickx.com/denyhosts-protecting-against-ssh-brute-force-attacks</link><description>&lt;p&gt;If you look after a remote linux box, the chances are you use SSH, in
order to connect to it you may even have to leave PORT 22 open to the
whole Internet !&lt;/p&gt;
&lt;p&gt;There are some basic security steps that you can do to protect SSH, such
as block the root user from logging in, and force users to use STRONG
authentication.&lt;/p&gt;
&lt;p&gt;Even after you've done all you can,
&lt;a href="http://freshmeat.net/projects/logwatch/"&gt;logwatch&lt;/a&gt; will report that
people are still wasting your time &amp;amp; resource by trying to break in !
This is where &lt;a href="http://denyhosts.sourceforge.net/"&gt;DenyHosts&lt;/a&gt; step in,
it's a small script (&lt;em&gt;daemon&lt;/em&gt;) that keeps an eye on your SSH log file,
if it spots someone trying to Brute Force Attack your SSH accounts, it
adds them to hosts.deny (&lt;em&gt;it's like a firewall for some applications&lt;/em&gt;)
and stops them from being able to connect.&lt;/p&gt;
&lt;p&gt;I'm using redhat, so a pre-built &lt;a href="http://dag.wieers.com/rpm/packages/denyhosts/"&gt;rpm is
available&lt;/a&gt;, if you
already have DAG setup, you can use...&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;yum install denyhosts
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I then had to run through the following steps (&lt;em&gt;as root&lt;/em&gt;).&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;mkdir /usr/share/denyhosts
mkdir /usr/share/denyhosts/data/
echo '127.0.0.1' &amp;gt; /usr/share/denyhosts/data/allowed-hosts
cd /usr/share/denyhosts
cp /usr/share/doc/denyhosts-2.6/denyhosts.cfg-dist ./denyhosts.cfg
cp /usr/share/doc/denyhosts-2.6/daemon-control-dist ./daemon-control
chmod 700 /usr/share/denyhosts/daemon-control
ln -s /usr/share/denyhosts/daemon-control /etc/init.d/denyhosts
ln -s /usr/share/denyhosts/denyhosts.cfg /etc/denyhosts.cfg
/sbin/chkconfig denyhosts on
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;once you've charged through that marathon, in /etc/denyhosts.cfg you may
want to take a look (&lt;em&gt;and change&lt;/em&gt;) the following settings (&lt;em&gt;Variables&lt;/em&gt;)&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;PURGE_DENY =
ADMIN_EMAIL =
SMTP_FROM = DenyHosts &amp;lt;nobody@localhost&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;finally once you're happy, start the DenyHosts service&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;/etc/init.d/denyhosts start
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now you're logwatch report will show how may tries they had, and then
Denied !&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Refused incoming connections: 1.2.3.4  (some.name.com ): 2 Time(s)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Of course one option commonly suggested is to change the SSH port number
from 22 to something else, where as this will reduce the amount of
attacks on the service, it does absolutely nothing to protect it; of
course you could do both, it's all a matter of choice :)&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">nick</dc:creator><pubDate>Thu, 12 Apr 2007 18:12:00 +0100</pubDate><guid isPermaLink="false">tag:www.linickx.com,2007-04-12:denyhosts-protecting-against-ssh-brute-force-attacks</guid><category>Fedora</category><category>ips</category><category>Linux</category><category>redhat</category><category>Security</category><category>ssh</category></item></channel></rss>