Cygwin

Cygwin
cygwin

GNU + Cygnus + Windows = cygwin

What Is Cygwin?

 * Cygwin is a Linux-like environment for Windows. It consists of two parts: A DLL (cygwin1.dll) which acts as a Linux API emulation layer providing substantial Linux API functionality.
 * A collection of tools which provide Linux look and feel.

The Cygwin DLL currently works with all recent, commercially released x86 32 bit and 64 bit versions of Windows, with the exception of Windows CE.

Note that the official support for Windows 95, Windows 98, and Windows Me will be discontinued with the next major version (1.7.0) of Cygwin.

What Isn't Cygwin?

 * Cygwin is not a way to run native linux apps on Windows. You have to rebuild your application from source if you want it to run on Windows.
 * Cygwin is not a way to magically make native Windows apps aware of UNIX ® functionality, like signals, ptys, etc. Again, you need to build your apps from source if you want to take advantage of Cygwin functionality.

Basic Cygwin Installation

 * 1) Download Cygwin from http://www.cygwin.com/
 * 2) * https://www.cygwin.com/setup-x86.exe
 * 3) * https://www.cygwin.com/setup-x86_64.exe
 * 4) Execute setup.exe
 * 5) Select "Install from Internet"
 * 6) Root directory "C:\cygwin"
 * 7) Local Package Directory "C:\cygwin\install"
 * 8) Select "Direct Connection"
 * 9) Select Download URL - http://mirrors.kernel.org  (http://mirrors.kernel.org/sourceware/cygwin/)
 * 10) The Installation will proceed
 * 11) Select desired packages, which can be done later.
 * 12) Copy setup.exe into the C:\cygwin\install folder for future use

Add c:\cygwin\bin to your PATH to be able to use Cygwin tools from 'cmd'.

Setup.exe Command Line Options
See Cygwin setup.exe command line options

Packages
See Cygwin Default Pacakges

See Cygwin Recommended Additional Packages

Command Line Package Installation
NOTE: On Windows 7, the shell has to be "Run As Administrator" to use setup.exe

Install additional packages: setup.exe -q -P [PACKAGE#1],[PACKAGE#2],[PACKAGE#N]
 * 1) by package:

setup.exe -q -C [CATEGORY#1],[CATEGORY#2],[CATEGORY#N]
 * 1) by category:


 * 1) -q - quiet mode, unattended (does not ask questions)
 * 2) -P - install specific package
 * 3) -C - install all packages in category

Common packages to install: (within shell) cd /install ln -s setup-x86_64.exe setup.exe

./setup.exe -q -P cron,\ cygrunsrv,shutdown,syslog-ng,sharutils,unzip,zip,vim,Perl,Python,bc,\ units,bind,curl,netcat,nc,nfs-server,openssh,ping,rsync,whois,ipcalc,util-linux,cpio,\ diffutils,gnupg,screen,time,links,lynx,wget,tree

If you get this error, you are probably running Windows 7 with UAC. Run Cygwin terminal with "Run as administrator". $ ./setup.exe -q -P wget -bash: ./setup.exe: Permission denied

To just update packages: cd /install ./setup.exe -q

Other Useful packages

 * subversion
 * git
 * mercurial

./setup.exe -q -P subversion,git,mercurial

Missing Packages or Tools
Missing programs:
 * killall
 * nmap
 * ntpdate
 * mail
 * sudo
 * telnet

tio
./setup.exe -q -P gcc-core,make

wget https://github.com/tio/tio/releases/download/v1.20/tio-1.20.tar.xz tar -avxf tio-1.20.tar.xz cd tio-1.20 ./configure make && make install

# OR

./setup.exe -q -P gcc-core,make,autoconf,automake

git clone https://github.com/tio/tio.git cd tio autoconf ./configure make && make install
 * 1) sh autogen.sh  # throws errors

See Linux/tio for usage.

services for Cygwin
List cygwin services: cygrunsrv -L

Install service: cygrunsrv -I [svc_name] ...

Remove service: cygrunsrv -R [svc_name]

Example server installation (crond): cygrunsrv -I crond -p /usr/sbin/cron.exe -a "-n" -u Administrator \ -d "Cygwin crond service" -f "Cygwin crond service"
 * 1) -I is install with service name
 * 2) -p is program path
 * 3) -a is arguments
 * 4) -d is "Name"
 * 5) -f is "Description"

See cygrunsrv help

syslog for Cygwin
Install packages: Admin - cygrunsrv  # to make windows services Admin - syslog-ng  # syslog service System - util-linux

Important Files: /etc/syslog-ng.conf /var/log/messages /usr/share/doc/syslog-ng/syslog-ng.conf.sample

Start/Stop Service: net start syslog-ng net stop syslog-ng

Wizard Install
Syslog Installation Wizard: /usr/bin/syslog-ng-config

This will create the /etc/syslog-ng.conf using a simple and clean config file emedded in the syslog-ng-config script (not from syslog-ng.conf.sample).

See syslog-ng-config output

See syslog-ng.conf default

Manual Install
Test service prior to installing Windows service, and fix any issues found: /usr/sbin/syslog-ng.exe

$ /usr/sbin/syslog-ng.exe Error opening configuration file; filename='/etc/syslog-ng.conf', error='No such file or directory (2)'

Create /etc/syslog-ng.conf:
 * See syslog-ng.conf default
 * or See /usr/share/doc/syslog-ng/syslog-ng.conf.sample

Install syslogd service: cygrunsrv -I syslogd -p /usr/sbin/syslog-ng -a "-F --fd-limit 256" -d "Cygwin syslogd service" \ -f "Cygwin syslogd service"
 * 1) -I is install with service name
 * 2) -p is program path
 * 3) -a is arguments
 * 4) -d is "Name"
 * 5) -f is "Description"

user creation
If you add users, make sure to run: mkpasswd -l >/etc/passwd

Example: net user root test12 /add net localgroup administrators root /add mkpasswd -l >/etc/passwd mkdir /home/root
 * 1) net user root * /add

typical commands
Reboot system reboot -r now

Wizard Installation
Installation: /usr/bin/ssh-host-config -y -w v net start sshd
 * 1) /usr/bin/ssh-host-config
 * 1) add users

Typical Answers: yes yes yes no yes v v

$ ssh-host-config --help usage: [OPTION]...

This script creates an OpenSSH host configuration.

Options: --debug -d            Enable shell's debug output. --yes   -y            Answer all questions with "yes" automatically. --no    -n            Answer all questions with "no" automatically. --cygwin -c Use "options" as value for CYGWIN environment var. --port  -p         sshd listens on port n.  --user   -u  privileged user for service. --pwd   -w   Use "pwd" as password for privileged user. --privileged          On Windows NT/2k/XP, require privileged user instead of LocalSystem for sshd service.

See ssh-host-config output

ssh-host-config and ssh-user-config

Manual Installation
touch /etc/sshd_config echo "UsePrivilegeSeparation no" >> /etc/sshd_config ssh-keygen -t rsa -f /etc/ssh_host_rsa_key

/usr/sbin/sshd
 * 1) run server

---

$ /usr/sbin/sshd /etc/sshd_config: No such file or directory

To fix: touch /etc/sshd_config

$ /usr/sbin/sshd.exe Privilege separation user sshd does not exist

To fix: echo "UsePrivilegeSeparation no" >> /etc/sshd_config

$ /usr/sbin/sshd.exe Could not load host key: /etc/ssh_host_rsa_key Could not load host key: /etc/ssh_host_dsa_key Disabling protocol version 2. Could not load host key sshd: no hostkeys available -- exiting.

To fix: (generate host keys) ssh-keygen -t rsa -f /etc/ssh_host_rsa_key

ssh-keygen.exe -t dsa -f /etc/ssh_host_dsa_key -N "" ssh-keygen.exe -t rsa1 -f /etc/ssh_host_key -N "" ssh-keygen.exe -t rsa -f /etc/ssh_host_rsa_key -N ""

TODO: finish notes

References:
 * Cygwin SSHD HowTo
 * Sshd on Windows - Noah.org

Cygwin is alternative to OpenSSH on Windows
Network Simplicity - OpenSSH on Windows:
 * "This project is shut down, but Michael Johnson has created a follow-up project to continue the work. You can get information at his website."


 * "This OpenSSH project is shutting down. I no longer have the time to maintain a package that is, for the most part, unnecessary due to improvements in the installation process of Cygwin. If you need some starter info on getting an OpenSSH server installed in the cygwin environment try this site, or the cygwin mailing list."

References:
 * OpenSSH on Windows

crond for Cygwin
Important Files: * windows crond service (See crond registry service * /var/cron/tabs/[USER] * /var/log/cron.log * ~/cron.log

Tools
Create user crontab: crontab -e

See cron log events (including windows event log): /usr/bin/cronevents

Start/Stop service: net start cron net stop cron
 * 1) service is 'cron' if using cygrunsrv
 * 2) or 'crond' if manually

Wizard Install
Cron service configuration: (See Cygwin Notes) cron-config

Suggestion: rename the "Display Name" to "CYGWIN Cron daemon" to match the "CYGWIN" prefix of the syslog-ng and sshd services. This will not break the service. May have to reboot to see the change in the MMC.

Start service: net start sshd

Manually Install
Run cron first to make sure there are no issues: $ /usr/sbin/cron.exe D

Note: if you do this before running as a service you may get this issue: /usr/sbin/cron: can't lock /var/run/cron.pid, otherpid may be 3796: Resource temporarily unavailable

Install crond service: cygrunsrv -I crond -p /usr/sbin/cron.exe -a "-n" -u Administrator \ -d "Cygwin crond service" -f "Cygwin crond service"
 * 1) -I is install with service name
 * 2) -p is program path
 * 3) -a is arguments
 * 4) -d is "Name"
 * 5) -f is "Description"

Start service: net start crond

References:
 * Installing Cron on Cygwin | New Media Logic
 * cygwin-cron.pdf

nmap for Cygwin
"Download nmap for windows at http://download.insecure.org/nmap/dist/nmap-3.95-win32.zip and extract it at /cygwin/bin. do the command "chmod +x+r nmap.exe" and use it. "

ln -s /cygdrive/c/Program\ Files/Nmap/nmap.exe nmap
 * 1) Download and install Nmap from http://nmap.org/download.html
 * 2) Create a link to namp in the /bin directory:

Cygwin/X
Cygwin/X

"Whether or not you already have Cygwin installed, you can add Cygwin/X to your installation by downloading the latest setup.exe, running setup, and selecting the 'xorg-x11-base' package from the 'X11' category."

NFS for Cygwin
Cygwin NFS Server HOWTO

Wizard Installation
nfs-server-config

The available mount points are listed here: /etc/exports

To start NFS after running the nfs-server-config: net start portmap net start nfsd net start mountd

After making changes to /etc/exports: net stop mountd net start mountd

From the client, to show mount points: showmount -e [SERVERHOST]

From the client, to mount a mount point: mount [SERVERHOST]:/cygdrive /mnt/[MOUNTPOINT]

To add cygdrive C: SERVER /nfs (ro,no_root_squash) CLIENT (both link or full path work) or
 * 1) ln -s /cygdrive/c /nfs
 * 2) vi /etc/exports:
 * 1) net stop mountd ; net start mountd
 * 1) mount [SERVERHOST]:/nfs /mnt
 * 1) mount [SERVERHOST]:/cygdrive/c /mnt
 * 2) umount /mnt

Python pip
Installation: wget https://bootstrap.pypa.io/get-pip.py python get-pip.py

note: On Cygwin64 it will fail silently. To get it to work: ./setup.exe -q -P libuuid-devel,binutils

Usage: pip install pep8 pip install http://sourceforge.net/projects/pychecker/files/pychecker/0.8.19/pychecker-0.8.19.tar.gz/download

References:
 * python - Pip install not functioning on windows 7 Cygwin install - Stack Overflow - http://stackoverflow.com/questions/21057931/pip-install-not-functioning-on-windows-7-cygwin-install
 * Installation — pip 1.5.6 documentation - https://pip.pypa.io/en/latest/installing.html

64bit vs 32bit
How to tell which shell you are in?

On a 64bit system, 'uname -a' within Cygwin will tell you the architecture of Cygwin, not the system:

64bit Cygwin: (x86_64) {noformat} $ uname -a CYGWIN_NT-10.0 alienware 2.2.1(0.289/5/3) 2015-08-20 11:42 x86_64 Cygwin {noformat}

32bit Cygwin: (i686) {noformat} $ uname -a CYGWIN_NT-10.0-WOW alienware 2.2.1(0.289/5/3) 2015-08-20 11:40 i686 Cygwin {noformat}

Mirror
Mirror cygwin: rsync -avrt rsync://mirrors.kernel.org/sourceware/cygwin/.

List of Mirrors - https://cygwin.com/mirrors.html#mirroradmin

cygwin1.dll was not found
Error: bash.exe - Unable To Locate Component This application has failed to start because cygwin1.dll was not found. Re-installing the application may fix this problem.

This dll should be in the C:\cygwin\bin folder. If it is not, then the installation was corrupt. To resolve, delete the Cygwin folder and reinstall Cygwin.

vim in Cygwin sucks
Try using the .vimrc to bring it to Linux standards. See vim