Cygwin

From Omnia
Jump to navigation Jump to search

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. Execute setup.exe
  3. Select "Install from Internet"
  4. Root directory "C:\cygwin"
  5. Local Package Directory "C:\cygwin\install"
  6. Select "Direct Connection"
  7. Select Download URL - http://mirrors.kernel.org (http://mirrors.kernel.org/sourceware/cygwin/)
  8. The Installation will proceed
  9. Select desired packages, which can be done later.
  10. 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

Determin Path to environment

Convert from Cygwin path to Windows path:

 cygpath -w ~

Silent Install

Powershell version:

setup-x86.exe ` --site http://cygwin.mirror.constant.com ` --no-shortcuts ` --no-desktop ` --quiet-mode ` --root "c:\cygwin64" ` --arch x86 ` --local-package-dir "c:\cygwin64\install" ` --verbose ` --prune-install ` --packages openssh,git,rsync,nano

-

Install batch file:

REM Powershell 2
powershell -Command "(New-Object Net.WebClient).DownloadFile('https://cygwin.com/setup-x86.exe', '%PROGRAMFILES%\cygwinx86\setup-x86.exe')"

REM Powershell 3
REM powershell -Command "Invoke-WebRequest https://cygwin.com/setup-x86.exe -OutFile setup-x86.exe"

"%PROGRAMFILES%\cygwinx86\setup-x86.exe" ^
--site http://cygwin.mirror.constant.com ^
--no-shortcuts ^
--no-desktop ^
--quiet-mode ^
--root "%PROGRAMFILES%\cygwinx86\cygwin" ^
--arch x86 ^
--local-package-dir "%PROGRAMFILES%\cygwinx86\cygwin-packages" ^
--verbose ^
--prune-install ^
--packages openssh,git,rsync,nano
REM Run this as administrator!
powershell (new-object System.Net.WebClient).DownloadFile('https://THE_URL/cyg.bat','%TEMP%\cyg.bat'); Start-Process "%TEMP%\cyg.bat"

ref: [1]

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:

# by package:
setup.exe -q -P [PACKAGE#1],[PACKAGE#2],[PACKAGE#N]
# by category:
setup.exe -q -C [CATEGORY#1],[CATEGORY#2],[CATEGORY#N]
# -q - quiet mode, unattended (does not ask questions)
# -P - install specific package
# -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
## sh autogen.sh  # throws errors
autoconf
./configure
make && make install

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):

# -I is install with service name
# -p is program path
# -a is arguments
# -d is "Name"
# -f is "Description"
cygrunsrv -I crond -p /usr/sbin/cron.exe -a "-n" -u Administrator \
  -d "Cygwin crond service" -f "Cygwin crond service"

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:

Install syslogd service:

# -I is install with service name
# -p is program path
# -a is arguments
# -d is "Name"
# -f is "Description"
cygrunsrv -I syslogd -p /usr/sbin/syslog-ng -a "-F --fd-limit 256" -d "Cygwin syslogd service" \
   -f "Cygwin syslogd service"

sshd for Cygwin

user creation

If you add users, make sure to run: [2]

mkpasswd -l >/etc/passwd

Example:

# net user root * /add
net user root test12 /add
net localgroup administrators root /add
mkpasswd -l >/etc/passwd
mkdir /home/root

typical commands

Reboot system

reboot -r now

Wizard Installation

Installation:

# /usr/bin/ssh-host-config
/usr/bin/ssh-host-config -y -w v
net start sshd
# 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 <options>  Use "options" as value for CYGWIN environment var.
  --port   -p <n>        sshd listens on port n.
  --user   -u <account>  privileged user for service.
  --pwd    -w <passwd>   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
# run server 
/usr/sbin/sshd

---

$ /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 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:

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:

# service is 'cron' if using cygrunsrv
# or 'crond' if manually
net start cron
net stop cron

Wizard Install

Cron service configuration: (See Cygwin Notes#cron-config output)

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:

# -I is install with service name
# -p is program path
# -a is arguments
# -d is "Name"
# -f is "Description"
cygrunsrv -I crond -p /usr/sbin/cron.exe -a "-n" -u Administrator \
  -d "Cygwin crond service" -f "Cygwin crond service"

Start service:

net start crond

References:

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. " [3]


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

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
# ln -s /cygdrive/c /nfs
# vi /etc/exports:
  /nfs (ro,no_root_squash)
# net stop mountd ; net start mountd

CLIENT (both link or full path work)
# mount [SERVERHOST]:/nfs /mnt
or
# mount [SERVERHOST]:/cygdrive/c /mnt
# 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:

Mercurial

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

Issues

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

Notes

See Cygwin/Notes

keywords