Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

How to use Unix/Linux commands at the Windows command prompt

A lot of us who use Linux at work/school or have always grown up using unix commands for years and more often than not, there might have been instances where a ls command comes more naturally than the dir command at the command prompt in Windows. For the most part, a lot of us work around this drawback using the excellent tool: Cygwin. Cygwin is available for windows users here.The Cygwin tools are ports of the popular GNU development tools for Microsoft Windows. They run thanks to the Cygwin library which provides the UNIX system calls and environment these programs expect.

With these tools installed, it is possible to write Win32 console or GUI applications that make use of the standard Microsoft Win32 API and/or the Cygwin API. As a result, it is possible to easily port many significant Unix programs without the need for extensive changes to the source code. This includes configuring and building most of the available GNU software . Even if the development tools are of little to no use to you, you may have interest in the many standard Unix utilities provided with the package. They can be used both from the bash shell (provided) or from the standard Windows command shell.

While Cygwin would be an obvious choice for many Unix/Linux power users, there is an excellent and a much simpler alternative to using Cygwin. In this article, we will show you how to run your Unix commands right in the windows command prompt.

For this, we will be using CoreUtils. CoreUtils is available through Sourceforge and is available for download here. If you look in here, there are a number of GNUWin32 packages available, the one we would be using is the CoreUtils package. CoreUtils is a collection of basic file, shell and text manipulation utilities of the GNU operating system. These are the core utilities which are expected to exist on every OS. And when I talk about File utilities, they include chgrp, chmod, cp, dd, du, ln, ls, mkdir, mv, rm, touch, vdir among others. A sample of the text utilities include cat, cksum, cut, join, md5sum, shasum, sort, split etc. The shell root commands include echo, chroot, hostname, nice, pathchk, tty, who, whoami and yes su. So it is pretty much the whole nine yards here… The direct link for download of the CoreUtils package available through SourceForge is available here.

Once installed, you will need to add the path to the utilities to your PATH environment variable. Follow the steps below to achieve this

1. Click on Start –> Run and enter sysdm.cpl to bring up the system properties Dialog

2. Click on the Advanced tab –> Environment variables button Path to environment variable

3. In the System Variables pane, scroll down to Path and then click on edit.

4. Under Edit System Variable, in the variable value, at the end of the line , type the following including the semicolon which separates the individual elements in the path variable. ;C:\Program Files\GnuWin32\bin

env variable properties

Congratulations !! You have now added the GNUWin directory to your path and Unix commands can now be executed directly from the command line and run natively on the Win32 command prompt without the need for any emulation layer as shown below using the example of dir vs ls

command prompt comparing dir vs lsDownloads and Sources

1. Download CYGWIN

2. Download CoreUtils

Error: Cannot retrieve repository metadata (repomd.xml ) for repository: updates-newkey.

  1. ISSUE: Unable to use yum to update on FTP100
  2. ERROR MESSAGE: Error: Cannot retrieve repository metadata (repomd.xml) for repository: updates-newkey. Please verify its path and try again
  3. SOLUTION:
  1. Downloaded the updated and signed fedora-release package.
  2. Verify that the package sha1sum matches 259165485c16d39904200b069873967e3eb5fa6e:

sha1sum fedora-release-9-5.transition.noarch.rpm

  1. Install the package via rpm:

su -c 'rpm -Uvh fedora-release-9-5.transition.noarch.rpm'

  1. Move on to importing the new key.

Import the new key

  1. Verify and import the new GPG key to your GPG keyring as per https://fedoraproject.org/keys.
  2. Import the key into the RPM database:

su -c 'rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-8-and-9'

  1. Use your update tool to get and install any new updates from the new location

Setup an FTP user account minus shells

It's important to give to your strictly FTP users no real shell account on the Linux system. In this manner, if for any reasons someone could successfully get out of the FTP chrooted environment, it would not have the possibility of executing any user tasks since it doesn't have a bash shell. First, create new users for this purpose;

These users will be the users allowed to connect to your FTP server.
This has to be separate from a regular user account with unlimited access because of how the chroot environment works. Chroot makes it appear from the user's perspective as if the level of the file system you've placed them in is the top level of the file system.

Use the following command to create users in the /etc/passwd file. This step must be done for each additional new user you allow to access your FTP server.

        [root@deep ] /# mkdir /home/ftp
[root@deep ] /# useradd -d /home/ftp/ftpadmin/ -s /dev/null ftpadmin > /dev/null 2>&1
[root@deep ] /# passwd ftpadmin

Changing password for user ftpadmin
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully

  • The mkdir command will create the ftp directory under the /home directory to handle all FTP users' home directories we'll have on the server.

  • The useradd command will add the new user named ftpadmin to our Linux server.

  • Finally, the passwd command will set the password for this user ftpadmin.

Once the home/ftp/ directory has been created you don't have to use this command again for additional FTP users.
  1. Edit the /etc/shells file, vi /etc/shells and add a non-existent shell name like null, for example. This fake shell will limit access on the system for FTP users.

              [root@deep ] /# vi /etc/shells

    /bin/bash
    /bin/sh
    /bin/ash
    /bin/bsh
    /bin/tcsh
    /bin/csh
    /dev/null
    /dev/null, This is our added no-existent shell. With Red Hat Linux, a special device name /dev/null exists for purposes such as these.

  2. Now, edit your /etc/passwd file and add manually the /./ line to divide the /home/ftp directory with the /ftpadmin directory where the user ftpadmin should be automatically chdir'd to. This step must be done for each FTP user you add to your passwd file.

              ftpadmin:x:502:502::/home/ftp/ftpadmin/:/dev/null
    To read:
              ftpadmin:x:502:502::/home/ftp/./ftpadmin/:/dev/null
    ^^
    The account is ftpadmin, but you'll notice the path to the home directory is a bit odd. The first part /home/ftp/ indicates the filesystem that should be considered their new root directory. The dot . divides that from the directory they should be automatically chdir'd. change directory'd into, /ftpadmin/.

Once again, the /dev/null part disables their login as a regular user. With this modification, the user ftpadmin now has a fake shell instead of a real shell resulting in properly limited access on the system.



http://www.faqs.org/docs/securing/chap29sec295.html

COUNTER