Showing posts with label cygwin. Show all posts
Showing posts with label cygwin. Show all posts

Sunday, June 04, 2017

Launch Emacs for Windows with Batch File using Emacs Configuration from Cygwin

I maintain a shared Emacs configuration under Linux and Cygwin. In Windows, I wanted to easily launch Emacs from the Desktop with the following goals.

  • Create a shortcut in the taskbar that launches Emacs for Windows
  • Have Emacs for Windows obey the Emacs configuration from Cygwin
  • Avoid opening extra console windows

Some prerequisites,


I created a file called c:\cygwin64\emacs.bat with the following contents.
c:\cygwin64\bin\run bash.exe -c ~/dotfiles/bin/emacs.sh

The file ~/dotfiles/bin/emacs.sh is a shell script that sits in my Cygwin directory. It is a wrapper script that calls Emacs for Windows if I'm running Cygwin.

It is assumed that the default Emacs configuration sits in the ~/.emacs file under Cygwin.

Pin the c:\cygwin64\emacs.bat script to your task bar. See below if you do not know how to do this. Clicking on it will open Emacs for Windows without any intervening console windows.

References

Saturday, May 05, 2012

Adding current user in Cygwin under a domain account

If you are in a domain, it is sometimes the case that running mkpasswd -d takes an extremely great amount of time. If you want to add only the current user, try the following.

mkpasswd -c >>/etc/passwd
mkgroup -c >>/etc/passwd


Create a home directory

mkdir /home/<username>

Reference (http://cygwin.com/ml/cygwin/2009-01/msg00709.html)

Monday, November 07, 2011

Pretty Cygwin icons

When creating a shortcut for Cygwin, the icon typically defaults to the standard terminal icon. Rather than using this black and white icon, you can have a more colorful one. Right click on the shortcut and select Properties->Change Icon. Point the icon path to the following file.

%SystemDrive%\cygwin\bin\cygicons-0.dll

Sunday, July 10, 2011

Installing sendmail in Cygwin

To enable the ability to send email from Cygwin, you must install sendmail. Cygwin provides two implementations of sendmail: exim and ssmtp. Either one can be used. The following text shows how to configure exim after it has been installed. In a future post, I will discuss how to send mail using sendmail.

Run the Cygwin setup.exe program, and install the exim package.

Open the Cygwin terminal with administrator privileges. To do this, right click on Cygwin.bat and select "Run as administrator." When the User Account Control dialog box is displayed, click Yes. In the Cygwin terminal, type the following commands.

localhost % exim-config
************************************************
This script sets some key parameters of the exim
installation and starts the exim daemon.
See the details in /usr/share/doc/Cygwin/exim-X-Y.README.
    Interrupt with ^D.

OK. No usernames contain spaces.

OK. The /etc/aliases file contains "postmaster".

Looking for the fully qualified primary hostname.
Is it "localhost"? (yes/no) yes
OK. Exim will autodiscover that name.

INFO: This version of Exim supports ipv6 by default.
      This feature is currently enabled.
Do you want to change that setting? (yes/no) no
INFO: Some programs expect /usr/sbin/sendmail to handle mail.
      Currently it does not exist.
Linking to exim may affect other programs such as cron.
Do you want to link /usr/sbin/sendmail to /usr/bin/exim ? (yes/no) yes
OK. Done.

Do you want to install the exim daemon as a service? (yes/no) no
WARNING: If running exim as a job, it may stop when you log out.

Do you want to start the exim daemon as a job now? (yes/no) no
OK. Type "/usr/bin/exim -bd -q15m" to start the exim daemon job.

INFO: The exim log files are in /var/log/exim.

When everything else fails,
    read /usr/share/doc/Cygwin/exim-X-Y.README,
    or look up the documentation on www.exim.org.
Many happy mailings :)

Friday, July 08, 2011

Library dependencies in Cygwin

To list the libraries on which a file depends, use cygcheck. The following command lists all the libraries used by the less program.

cygcheck less

To search for the package containing a particular library, check the Cygwin database http://cygwin.com/packages/ or use cygcheck with the -p option. The following command shows the package which provides the file /bin/foo.dll.

cygcheck -p /bin/foo.dll

Monday, July 04, 2011

Querying the Cygwin package database

If you ever need to query the Cygwin package database, cygcheck is the command to use. For example, you may want to determine the package containing a certain program in which you are interested in installing.

Find the package containing a particular file.

cygcheck -f /usr/bin/less
List the contents of a package.

cygcheck -l less
Search for the regular expression in the entire Cygwin database.

cygcheck -p 'less\.exe'

Thursday, June 30, 2011

Additional useful Cygwin packages to install

The base installation of Cygwin falls short of installing some useful packages I frequently use. Here is the list of additional packages I install.

aspell : provides a spell check
aspell-en : provides an English word list for the spell check
bash-completion : tab completes SSH login names for example
bc : calculator
bind-utils : dig, host
emacs : editor
keychain manages ssh-agent
ncurses : provides clear
nc : connect networks
openssh : provides SSH
ping: provides ping
procps : provides top
rsync : mirror files
rxvt : better terminal
unzip : unzip files
util-linux : provides getopt
vim : editor
wget : retrieve files from the Internet
zip : zip files

Thursday, June 23, 2011

Installing SSH server in Cygwin on Windows 7

The following steps document how to install SSH server in Cygwin on Windows 7.

Run the Cygwin setup.exe program, and install the openssh package.

If you wish to install sshd as a service, you should run the Cygwin terminal with administrator privileges. To do this, right click on Cygwin.bat and select "Run as administrator." When the User Account Control dialog box is displayed, click Yes. In the Cygwin terminal, type the following commands.

$ ssh-host-config 
*** Info: Generating /etc/ssh_host_key
*** Info: Generating /etc/ssh_host_rsa_key
*** Info: Generating /etc/ssh_host_dsa_key
*** Info: Generating /etc/ssh_host_ecdsa_key
*** Info: Creating default /etc/ssh_config file
*** Info: Creating default /etc/sshd_config file
*** Info: Privilege separation is set to yes by default since OpenSSH 3.3.
*** Info: However, this requires a non-privileged account called 'sshd'.
*** Info: For more info on privilege separation read /usr/share/doc/openssh/README.privsep.
*** Query: Should privilege separation be used? (yes/no) yes
*** Info: Updating /etc/sshd_config file

*** Warning: The following functions require administrator privileges!

*** Query: Do you want to install sshd as a service?
*** Query: (Say "no" if it is already installed as a service) (yes/no) yes
*** Query: Enter the value of CYGWIN for the daemon: []
*** Info: On Windows Server 2003, Windows Vista, and above, the
*** Info: SYSTEM account cannot setuid to other users -- a capability
*** Info: sshd requires.  You need to have or to create a privileged
*** Info: account.  This script will help you do so.

*** Info: You appear to be running Windows XP 64bit, Windows 2003 Server,
*** Info: or later.  On these systems, it's not possible to use the LocalSystem
*** Info: account for services that can change the user id without an
*** Info: explicit password (such as passwordless logins [e.g. public key
*** Info: authentication] via sshd).

*** Info: If you want to enable that functionality, it's required to create
*** Info: a new account with special privileges (unless a similar account
*** Info: already exists). This account is then used to run these special
*** Info: servers.

*** Info: Note that creating a new user requires that the current account
*** Info: have Administrator privileges itself.

*** Info: The following privileged accounts were found: 'cyg_server' .

*** Info: This script plans to use 'cyg_server'.
*** Info: 'cyg_server' will only be used by registered services.
*** Query: Do you want to use a different name? (yes/no) no
*** Query: Please enter the password for user 'cyg_server':
*** Query: Reenter:

*** Info: The sshd service has been installed under the 'cyg_server'
*** Info: account.  To start the service now, call `net start sshd' or
*** Info: `cygrunsrv -S sshd'.  Otherwise, it will start automatically
*** Info: after the next reboot.

*** Info: Host configuration finished. Have fun!

If you answer yes to install sshd as a service above, you can start the service now with the following command.

$ net start sshd
The CYGWIN sshd service is starting.
The CYGWIN sshd service was started successfully.

Testing

Try logging into locahost from the computer on which the SSH server was installed. If you choose to log in with a password, make sure you have set a Windows password for your account before testing. From a Cygwin shell, type the following.

$ ssh localhost

Troubleshooting

If you run into any problems, check the permissions of the following files and directories.

$ ls -ld /etc/passwd /etc/group /var /var/log/sshd.log /var/empty
-rw-r--r--  1 <user>     None 1089 Jan 01 00:01 /etc/group
-rw-r--r--  1 <user>     None 1072 Jan 01 00:01 /etc/passwd
drwxr-xr-x+ 1 <user>     root    0 Jan 01 00:01 /var
drwxr-xr-x+ 1 cyg_server root    0 Jan 01 00:01 /var/empty
drwxr-xr-x+ 1 cyg_server None    0 Jan 01 00:01 /var/log/sshd.log

If the permissions of these files look different from the above, run the following commands prior to the installation.

$ chmod +r  /etc/passwd
$ chmod u+w /etc/passwd
$ chmod +r  /etc/group
$ chmod u+w /etc/group
$ chmod 755 /var 
$ touch /var/log/sshd.log
$ chmod 664 /var/log/sshd.log

Wednesday, June 22, 2011

Debugging SSH server in Cygwin

If you are debugging a SSH connection, you may need to run sshd by hand (instead of as a service) and enable debugging output. Doing so allows you to track exactly why a connection is failing to establish. However, if you try to run sshd by hand, you may get the following message.
% cygrunsrv.exe --stop sshd
% /usr/sbin/sshd.exe -D
Could not load host key: /etc/ssh_host_ecdsa_key
/var/empty must be owned by root and not group or world-writable.
To fix this, make the user starting the sshd service the owner of /var/empty.
% ls -ld /var/empty
drwxr-xr-x+ 1 cyg_server root 0 May  7  2010 empty
% chown <user> /var/empty
Now, start sshd again.
% /usr/sbin/sshd.exe -D
When you are done debugging and are ready to run sshd again as a service, change the owner of /var/empty to cyg_server.
% chown cyg_server /var/empty
% cygrunsrv.exe --start sshd
 Note: you must have administrator privileges to run cygrunsrv.exe.

Tuesday, June 14, 2011

A more featureful terminal in Cygwin

The default Cygwin terminal uses the Windows terminal. If you have ever used the Windows terminal, you will know that it not support some of the basic functionality found in other terminals like Xterm. To get a more featureful terminal without installing X, install the Rxvt package. Then replace the contents of your cygwin.bat file with the following batch script. This example runs a bash login shell when the terminal starts. Note that the login (-l) flag is important because it tells bash to source /etc/profile which in turn will source the user's .bash_profile file.

@echo off
C:
chdir C:\cygwin\bin
rxvt -bg black -fg white -fn "Lucida Console"-11 -geometry 110x75 -e /bin/bash -l -i

Kill Windows processes from Cygwin

A previous post discussed how to list Windows processes from Cygwin. To kill those processes, use the following command. Note that the kill command is actually /bin/kill and not /usr/bin/kill. Make sure you are using the right binary.
/bin/kill -f <process id>

Monday, June 13, 2011

List Windows processes in Cygwin

Cygwin can list Cygwin processes as well as Windows processes. To see a list of the running Windows processes, run the following command. Note the capitalized W.
ps -W

Sunday, June 12, 2011

Where are clear and top in Cygwin?

Clear and top are not installed as part of the default Cygwin installation. Clear is part of the ncurses package, and top is part of the procps package. Install these additional packages to get clear and top.

Home away from /home

Cygwin is a collection of tools to provide the linux feel in Windows. To install Cygwin, download setup.exe from the Cygwin webpage and store it in a folder like c:/cygwin. Run setup.exe and follow the default prompts. After the installation is finished, double click on c:/cygwin/cygwin.bat to launch a Bash shell in a Cygwin terminal.

Cygwin (webpage)
Cygwin setup.exe (download)