Crypt Encryption Function Usage

crypto(3) is a function that provides basic criptography. It is at a so basic level that for serious work other than that of generating a shadowed password on the system, it is not recommended (as per a statement in its own man page).

The function is declared in the crypt.h file:

extern char *crypt (__const char *__key, __const char *__salt)

The input is a raw password string and a salt string, which is an additional value that provides a certain level of randomness to crypto’s hash generation process, so that there is not a single hash that may be produced for the same password, but several instead. If one provides a salt A, the output for the password X is Y whereas another salt B is passed, the output hash cannot be Y anymore, it will be some other hash Z.

I made a program in C which uses it, whose source code file I named cryptifier.c that has the following content:

#include <crypt.h>
#include <stdio.h>
#define _XOPEN_SOURCE
#include <unistd.h>
 
int main(int argc, char **argv) {
 
  const char *k = (const char *) argv[1];
  const char *s = (const char *) argv[2];
  char* r;
 
  printf("'%s' with salt '%s' generates '%s'\n", k, s, crypt(k, s));
 
  return 0;
 
}

The output of this function can be served as an input argument for useradd command’s -p option as described in a previous post.

IMPORTANT remark: when compiling a program that uses crypt.h now and having libc-6 it is necessary to specify -lcrypt (for libcrypt) on the gcc command line as libc-5 used to have crypt() in libc, whereas libc-6 has it in libcrypt (this is very old change, dated at least of 1998: source post).

Ruby Symbols with Spaces

I saw code saying “I have spaces”.to_sym to convert a String object to a symbol, but one can also use the form :’I am a symbol with spaces’.

See:

1.9.3-p0 :005 > :’this is a test’
=> :”this is a test”
1.9.3-p0 :006 > :’this is a test’.class
=> Symbol
1.9.3-p0 :007 > :’this is a test’.to_s
=> “this is a test”

This was also tested in ruby-1.8.7-p357.

Command Example for useradd

The useradd command is a tool that provides sysadmins with the capability of adding new users (a.k.a. logins) to the system. The generic form of the command is this:

useradd -c 'COMMENT' -d 'HOME' -m -p 'CRYPT_STRING' -s 'SHELL' LOGIN
  • COMMENT is used generally for user information such as full name, phone number etc.
  • HOME is the home folder e.g. /home/user.
  • CRYPT_STRING string generated by the crypt(3) function (libcrypt, a component of glibc, the GNU C Library).
  • SHELL is the default shell for the user.
  • LOGIN is for the new username in question.

The -m option creates the user’s home directory if it does not exist.

Example:

useradd -c 'John Doe' -d /home/johndoe -m -p 'ABiELdbxGY2fY' -s '/bin/ksh' johndoe

John Doe just got himself a new account with the /home/johndoe home/login directory, created (-m) if not present, with CRYPT_STRING ‘ABiELdbxGY2fY’ generated by the crypt(3) function for the (simplest and unbelievably most commonly used) password ’123456′ with salt ‘AB’. The default login shell for this account is ksh (-s ‘/bin/ksh’). And last, the username, johndoe.

Go on and create some users on your grid.

Add CDROM or ISO Packages to Red Hat Enterprise Linux 5.7

Red Hat generally provides a stable Linux distribution in its currently supported releases. And one might want to only use the packages that came along with the distribution media i.e. a cdrom or an .iso file containing that cd’s image.

To be able to use a CD’s or .iso file’s packages in RHEL (Red Hat Enterprise Linux) 5.7, create this file in /etc/yum.repos.d/:

[user@localhost yum.repos.d]$ cat redhat_cdrom.repo
[redhat_cdrom]
name=Red Hat Enterprise Linux $releasever - CD-ROM
baseurl=file:///media/rhel/Server
enabled=1
gpgcheck=1
gpgkey=file:///media/rhel/RPM-GPG-KEY-redhat-release

This is assuming you had mounted the cdrom or the distribution’s .iso file to the /media/rhel directory.

Then do:

# yum update

And then pick up the desired software and install it:

# yum install <packages>

That is all.