Windows: TaskKill – Kill Process by PID, Name, Port – CMD

Sometimes when an application in Windows hangs, freezes and stops responding the only way to terminate it is to kill from the command-line.

The taskkill command in Windows serves for terminating tasks by name or by process id (PID).

In this note i am showing how to find and kill a process by its name or by PID and how to identify a process by the listening port.

I am also showing how to troubleshoot “The process could not be terminated” and “Access denied” errors. (more…)

Windows: Get Exit Code (ErrorLevel) – CMD & PowerShell

Every command or application returns an exit status, also known as a return status or exit code.

A successful command or application returns a 0, while an unsuccessful one returns a non-zero value that usually can be interpreted as an error code.

In Linux you can get the exit status of a last command by executing echo $?.

In this article i will show how to get the return code from the last console command or application in Windows using the command-line prompt (CMD) or the PowerShell. (more…)

Windows: Set Environment Variable – CMD & PowerShell

What is an environment variable in Windows? An environment variable is a dynamic “object” containing an editable value which may be used by one or more software programs in Windows.

In this note i am showing how to set an environment variable in Windows from the command-line prompt (CMD) and from the Windows PowerShell.

In the examples below i will set an environment variable temporary (for the current terminal session only), permanently for the current user and globally for the whole system. (more…)

Windows: `Grep` Equivalent – CMD & PowerShell

The grep command in Linux is widely used for parsing files and searching for useful data in the outputs of different commands.

The findstr command is a Windows grep equivalent in a Windows command-line prompt (CMD).

In a Windows PowerShell the alternative for grep is the Select-String command.

Below you will find some examples of how to “grep” in Windows using these alternatives. (more…)

HowTo: Mount Remote Windows Partition (Share) under Linux

The article describes how to mount CIFS shares manually. The shares can be on a Windows computer or on a Linux/UNIX server running Samba.

Prerequisites

1. Install cifs-utils, if it hasn’t been installed yet.

This package contains tools for mounting shares on Linux using the SMB/CIFS protocol.

# yum install cifs-utils
# sudo apt-get install cifs-utils

2. Check that NetBIOS service is running and reachable on the remote host.

Port 139 TCP – NetBIOS (Windows File and Printer Sharing).
It allows applications on separate computers to communicate over a local area network.

You can test it with telnet or nmap.

# nmap -p T:139 172.16.10.1
Nmap scan report for 172.16.10.1
Host is up (0.0011s latency).
PORT    STATE SERVICE
139/tcp open  netbios-ssn
MAC Address: 00:00:00:00:00:00 (Unknown)

# telnet 172.16.10.1 139
Trying 172.16.10.1...
Connected to 172.16.10.1.
Escape character is '^]'.

Mounting Remote Windows Share

Run all commands as root (use sudo).

Create mount point

# mkdir -p /mnt/win

Mount password protected network folder

# mount -t cifs //IP/SHARE /mnt/win/ -o dom=DOMAIN,user=USER,pass=PASS
e.g.
# mount -t cifs //172.16.10.1/private /mnt/win/ -o user=admin,pass=secret

You can use Computer/Server Name instead of IP Address.

  • ‘mount -t cifs’ – mount using the Common Internet File System (CIFS);
  • ‘-o’ – options passed to mount command;
  • ‘user=’ – username;
  • ‘pass=’ – password;
  • ‘dom=’ – domain e.g WORKGROUP (if server in domain).

Mount unprotected (guest) network folder

# mount -t cifs //IP/SAHRE /mnt/win/ -o guest
e.g.
# mount -t cifs //172.16.10.1/public /mnt/win/ -o guest
  • ‘guest’ – don’t prompt for a password.

Mount entire drive

# mount -t cifs //IP/DRIVE$ /mnt/win/ -o dom=DOMAIN,user=USER,pass=PASS
e.g.
# mount -t cifs //172.16.10.1/c$ /mnt/win/ -o user=admin,pass=secret

Unmount share

# umount /mnt/win/

Moving SSL Certificate from IIS to Apache

This procedure will help you to move or copy your SSL certificate, installed on an IIS server to an Apache server.

Step 1: Export IIS certificate into a .PFX file

  • Run mmc.exe
  • Click the ‘Console’ menu and then click ‘Add/Remove Snap-in’.
  • Click the ‘Add’ button and then choose the ‘certificates’ snap-in and click on ‘Add’.
  • Select ‘Computer Account’ then click ‘Next’.
  • Select ‘Local Computer’ and then click ‘OK’.
  • Click ‘Close’ and then click ‘OK’.
  • Expand the menu for ‘Certificates’ and click on the ‘Personal’ folder.
  • Right click on the certificate that you want to export and select ‘All tasks’ -> ‘Export’.
  • A wizard will appear. Make sure you check the box to include the private key and continue through with this wizard until you have a .PFX file.

Step 2: Extract the private key

Export the private key file from the .PFX file.

$ openssl pkcs12 -in filename.pfx -nocerts -out key.pem

Step 3: Extract the certificate file

Export the certificate file from the .PFX file.

$ openssl pkcs12 -in filename.pfx -clcerts -nokeys -out cert.pem

Step 4: Remove the passphrase

This command removes the passphrase from the private key so Apache won’t prompt you for your passphase when it starts.

$ openssl rsa -in key.pem -out server.key

Extra Steps

Make sure that the following lines are present in your apache virtual host configuration file and they are correct:

SSLEngine on
SSLOptions +StrictRequire
SSLCertificateFile /path/to/certificate/cert.pem
SSLCertificateKeyFile /patch/to/key/server.key

Don’t forget to restart apache at the end.