Cygwin: Difference between revisions

From miki
Jump to navigation Jump to search
(→‎Cygwin Useful commands: getclip, putclip)
Line 146: Line 146:
* Use '''rxvt''' as terminal emulator instead of standard console window.
* Use '''rxvt''' as terminal emulator instead of standard console window.
* The <tt>+</tt> that appears next to file permission in '''ls''' output means that there are other permissions for the file (use '''getfacl''' on the file to see them)
* The <tt>+</tt> that appears next to file permission in '''ls''' output means that there are other permissions for the file (use '''getfacl''' on the file to see them)
<div style="padding-left:2em;"><pre>
<pre>
-rwxr-x---+ 1 beq06659 Users 2555 Oct 10 23:32 inetd.conf* #More permissions set (getfacl inetd.conf to see them)
-rwxr-x---+ 1 beq06659 Users 2555 Oct 10 23:32 inetd.conf* #More permissions set (getfacl inetd.conf to see them)
-rwxr-x--- 1 beq06659 Users 706 Nov 8 01:27 initscript*
-rwxr-x--- 1 beq06659 Users 706 Nov 8 01:27 initscript*
</pre>
</pre>
</div>
* '''Clipboard''' integration
* '''Clipboard''' integration
** To enable ''clipboard'' usage in Cygwin X Server, use option <tt>--clipboard</tt> with command <tt>xwin</tt>.
** To enable ''clipboard'' usage in Cygwin X Server, use option <tt>--clipboard</tt> with command <tt>xwin</tt>.
** Device <tt>/dev/clipboard</tt> can be used for command-line manipulation of the clipboard (note that <tt>/dev/clipboard</tt> is not listed in <tt>/dev</tt> directory):
** Device <tt>/dev/clipboard</tt> can be used for command-line manipulation of the clipboard (note that <tt>/dev/clipboard</tt> is not listed in <tt>/dev</tt> directory). The commands <tt>getclip</tt> and <tt>putclip</tt> can be used for the same purpose (package [http://cygwin.com/packages/cygutils/ cygutils]):
<source lang="bash">
<div style="padding-left:3em;"><source lang="bash">
$ cat myfile >/dev/clipboard # To copy some text to the clipboard
$ cat myfile >/dev/clipboard # To copy some text to the clipboard
$ cat myfile | putclip # ... same effect
$ cat /dev/clipboard # To print the content of the clipboard
$ cat /dev/clipboard # To print the content of the clipboard
$ getclip # ... same effect
</source>
</source></div>


== Cygwin Useful commands ==
== Cygwin Useful commands ==

Revision as of 10:31, 18 November 2008

Packages

Creating a local setup.ini

Packages in Cygwin can be installed from repositories. The content of these repositories is described in a file setup.ini. Each package in the repository is made of one or more .bz2 files (the actual package) and a file setup.hint (spec) describing the content of the package. The setup.ini file of the repository is actually a compilation of all setup.hint files in the repository along with additional information. Cygwin apparently does not want to install a package from a single .hint file (or at least have not found how to do so). In that case you need to generate the setup.ini file. Here's an example how this can be done.

Example is based on package recode v3.6.1.

  • Download the package above, and create following directory structure within Cygwin Local Package Directory (where setup.ini location is already shown).
.
|-- http%3a%2f%2fftp....
|   ...
`-- local
    |-- release
    |   `-- recode
    |       |-- recode-3.6-1-src.tar.bz2
    |       |-- recode-3.6-1.tar.bz2
    |       |-- recode-devel
    |       |   |-- recode-devel-3.6-1.tar.bz2
    |       |   `-- setup.hint
    |       `-- setup.hint
    `-- setup.ini
  • Create the file ./local/setup.ini with the following content:
# File manually generated on 20081105.
# setup-timestamp and setup-version are completely fake...
setup-timestamp: 1214338445
setup-version: 2.573.2.2

@ recode
sdesc: "GNU recode utility"
ldesc: "The program recognizes or produces approx. 150 character sets and can convert almost any character set to almost  any other."
category: text
requires: cygwin libintl3
version: 3.6-1
install: release/recode/recode-3.6-1.tar.bz2 838836 c185a17d8e1eb964611d26cbfe9b0e05
source: release/recode/recode-3.6-1-src.tar.bz2 1731299 83b0f5940aa5d2a82355586b6d977bab
  • (in gray) First the header
  • (in black) Then entry giving the package name
  • (in red) Then a copy-paste from setup.hint file.
  • (in green) Then the version (derived from package name)
  • (in blue) And finally two entries for binary and source package, giving for each: location of .bz2 file, the file size in bytes, the md5 checksum (as given by md5sum).

When done, simply install the package by running Cygwin setup.exe, asking to Install from Local Directory. Cygwin will see the new file setup.ini, and proposes for install the packages listed inside.

Troubleshooting

Cygwin

  • Look for multiple copies of the cygwin DLL cygwin1.dll. Removes all copies that are not in the cygwin install directory (usually c:\cygwin).
  • List of interfering software:
    • NoMachine NX Client - installs a custom version of the Cygwin DLL which can cause multiple interferences:
      • Cygwin crashes when multiple instances are launched.
      • Running cygwin commands (like ls) in a NT command shell when another instance of cygwin is running creates application error (Memory cannot be "read").
      • setup.exe fails because it runs several instances of bash.
    • SysInternals' Process Monitor
      • All back-quoted commands or $() commands in scripts fail until Windows is restarted

Missing DLL using strace

strace can be used to check whether an application needs a .DLL but cannot find it. This error is not reported by default on cygwin, so an application may just leave without any message, giving the impression that it simply does nothing. strace on the other hand will report about the missing .DLL. To solve the problem, install the .DLL somewhere in your PATH, or edit the PATH to include the .DLL location.

Example ([1]):

$ strace /usr/local/sbin/authtest                   # This will open a dialog box to complain about DLL.
$ export PATH=$PATH:/usr/local/lib/bin
$ /usr/local/sbin/authtest ausername

Administration

Adding Users

Create the user in Windows User Management first, then use command mkpasswd to add it to Cygwin environment.

$ net user <username> <password> /add /yes
$ net localgroup <an_local_group> <username> /add
$ mkpasswd -l -u <username> >> /etc/passwd

Installing a Service

Reference: Cygwin inetutils-1.5 OLD-README

Use cygrunsrv to install a Cygwin process as a service in Windows. Some examples:

$ cygrunsrv -I inetd -d "CYGWIN inetd" -p /usr/sbin/inetd -a -D
$ cygrunsrv --install imapd --desc "Courier IMAP daemon" --disp "CYGWIN imapd" \
  --path /usr/local/sbin/imapd-service.sh --termsig QUIT --type auto --shutdown

By default this will install the service to run under account SYSTEM (LocalSystem), who is the user that has all the required permission up to Windows XP. For Windows 2003 Server or Windows Vista, see below.

Start/Stop the service

Manually starting and stopping is possible via

$ net start <service>
$ net stop <service>

Creating a Privileged User in Windows 2003, Windows Vista

Beginning with Windows 2003 Server and Windows Vista, the SYSTEM user is lacking the "Create a token object" right, which is required to change the user without providing the password. On these systems you have to create an admin user account with special additional user rights. You can use the Cygwin tool editrights or the local/domain security policy mmc snap in to set these rights:

Create a token object
Act as part of the operating system
Replace process level token
Increase quotas
Logon as a service

Get a Bash shell owned by another user

For instance, to open a Bash window as user localuser (you'll need to type in the user's password)

$ runas /user:localuser c:\cygwin\Cygwin.bat

Another method is to apply the same trick used to log as user SYSTEM (see below). This trick is even better since it doesn't require the user password, and hence would enable privilege escalation. However Windows security system prevents a process running as a user without providing the user password to connect to network shares.

Get a Bash shell owned by SYSTEM

This is a trick I found to easily open a Bash windows as user SYSTEM. First create a dummy service bashsystem:

$ cygrunsrv --install bashsystem --desc "Bash SYSTEM" --disp "CYGWIN bashsystem" --path /Cygwin.bat --type manual --interactive

Next, to open a Bash shell as user SYSTEM:

$ net start bashsystem

Miscellaneous

  • Reference Cygwin documentation can be found in /usr/share/doc/cygwin-doc-1.4.
  • Interesting post about the 'su' command, explaining why there is no 'su' in Cygwin, and how 'ssh' overcomes this.
    • Other relevant post.
  • Use rxvt as terminal emulator instead of standard console window.
  • The + that appears next to file permission in ls output means that there are other permissions for the file (use getfacl on the file to see them)
-rwxr-x---+ 1 beq06659 Users 2555 Oct 10 23:32 inetd.conf*       #More permissions set (getfacl inetd.conf to see them)
-rwxr-x---  1 beq06659 Users  706 Nov  8 01:27 initscript*
  • Clipboard integration
    • To enable clipboard usage in Cygwin X Server, use option --clipboard with command xwin.
    • Device /dev/clipboard can be used for command-line manipulation of the clipboard (note that /dev/clipboard is not listed in /dev directory). The commands getclip and putclip can be used for the same purpose (package cygutils):
$ cat myfile >/dev/clipboard                         # To copy some text to the clipboard
$ cat myfile | putclip                               # ... same effect
$ cat /dev/clipboard                                 # To print the content of the clipboard
$ getclip                                            # ... same effect

Cygwin Useful commands

id
Use command id to print user identity
getclip
Read from the Windows clipboard and write it to standard output (same as cat /dev/clipboard)
getfacl
Display file and directory access control lists (ACLs).
putclip
Read standard input and write into windows clipboard (same as cat >/dev/clipboard)