Showing posts with label ssh. Show all posts
Showing posts with label ssh. Show all posts

November 22, 2014

Setting up Git, SVN, curl and SSH on Windows using Cygwin terminal

I have previously mentioned that on my home computer, which is a Windows-running machine, I use Cygwin shell with a Console2 terminal. I have gotten used to Unix commands and infrastructure as I use them at work, and the Windows CLI just felt... well, flat in comparison.

Cygwin and Console2 are a nice remedy to implement a familiar interface for Windows. Let's start with Cygwin.

In their own words, Cygwin is "a large collection of GNU and Open Source tools which provide functionality similar to a Linux distribution on Windows". And frankly, this is the least finicky way I've been able to use Git on Windows. A lot of other GUI-based Git interfaces are pretty bad, and it's always better practices to learn and know the command line commands. So, speaking of, once you downloaded Cygwin, you choose your install directory, as well as a downloaded packages directory - it is here that "modules" such as Git gets installed into Cygwin. Get to know and love the Packages interface in Cygwin, chances are that if you are missing a module and need to install it later, you will be running Cygwin's installation program again (which now skips right to the packages window) to add what you need.

For a first-time install, I usually kick off my setup with a few choice packages such as:

  • vim (ironically for a UNIX emulator, this is actually not enabled by default)
  • OpenSSH
  • AutoSSH
  • PHP interpreter
  • curl
  • PHP-curl
  • Git (be sure to select the ca-certificates and libsasl2 packages as well - oddly they are not chosen as dependencies (unless you install the curl package as above). See here for more info, else you'll be running into "cannot open shared object file: No such file or directory" HTTPS git errors!)
  • Git/SVN
  • lib-mcrypt

These make it convenient to run commands straight from the Cygwin shell, for example if I need to run a quick cURL call or something. The SSH client is pure command line, so no need to fiddle around with crappy Windows GUI clients or yet another terminal emulator like PuTTY.

After selecting your desired Cygwin packages, you can complete the installation, noting the prompt to install dependencies for your selected packages. I usually go back and disable a few at this point, because - for example - blanket enabling the entire PHP5 package would then enable other packages like PHP5-apache2, which then have their own dependencies like the large Apache2 package which I personally won't need at all.

After installing, you can open your Cygwin shell, and see something like this message on the first load:
Copying skeleton files.
These files are for the users to personalise their cygwin experience.

They will never be overwritten nor automatically updated.

'./.bashrc' -> '/home/User//.bashrc'
'./.bash_profile' -> '/home/User//.bash_profile'
'./.inputrc' -> '/home/User//.inputrc'
'./.profile' -> '/home/User//.profile'

User@location ~
$ |

Right now, you're probably thinking that it's nice to have a UNIX shell, but the default Windows terminal that still wraps it is not very nice. I am of the same opinion. In the next post we will spruce things up a bit with Console2, entirely replacing the vanilla cmd terminal that the Cygwin shell still defaults to, and in a future post go over some Cygwin-specific tips.

September 2, 2014

How to set up SSH, using a Raspberry Pi as an example

SSH is a versatile and secure way of connecting to other devices, regardless of host/client operating system. Here's how it's done. I'll just use my Rasberry Pi as an example of how to do this, but these steps can be applied to any UNIX environment.

  1. See this article if for some reason SSH isn't already enabled on your Pi.
  2. Create your keys on your host machine if you haven't yet (see RSA vs DSA for key type info):
  3. mkdir ~/.ssh
    ssh-keygen -t rsa
  4. It's OK to use blank password defaults, unless you want the extra layer of security.
  5. Copy the public key to your Pi (replace the IP below with whatever your Pi's address is; use ifconfig on your Pi if needed to figure it out):
    scp ~/.ssh/id_rsa.pub pi@192.168.0.xx:~
  6. Connect to your Pi, being prompted still for your password one final time before kicking in your authentication keys:
    
    // SSH in from the host:
    ssh pi@192.168.0.xx
    // Enter your password, for the last time
    // Finally, pipe the SCP'ed public key into the authorized_keys file:
    cat ~/id_rsa.pub >> ~/.ssh/authorized_keys

Now you can log into your Pi from your host machine, securely, without being prompted for a password again.

April 1, 2014

Enable SSH access for Synology DSM

This assumes you already have an SSH client installed and set up.

From Control Panel -> Terminal & SNMP, select "Enable SSH service"



Next, enable "user home service" at Control Panel -> User -> Advanced tab, so that users can actually SSH login to somewhere useful:



Next, enable permissions for SSH-capable users to their "homes" folder:



You can now log in via terminal like:

ssh username@ip-address

Be sure that your user has login privileges. If they don't, SSH in as root, and set them up:


ssh root@ip-address
//...Logging on to the NAS...
sudo vi /etc/passwd

Change the end of the listed user's line from /sbin/nologin to /bin/ash to permit login.

Interesting read regarding security:
http://www.eldemonionegro.com/blog/archivos/2012/08/19/how-to-securely-activate-ssh-into-your-synology-diskstation-with-ssh-keys-and-no-root-login