Total Pageviews

Thursday, October 11, 2012

Changing Passwords on Multiple Machines



In the past, when it came to password changes for all users, we had to log into each machine, and manually change the password for each user. Not only was this time consuming, but subject to human error such as incorrect passwords, which in turn could cause an account to be locked out. In the past I have used NIS, but that was deemed to be a security problem. I looked around a small expect script that when run and supplied a username and password, would in turn run the passwd program to generate a new password for the user. That was the first step, but it needed to be surrounded by a lot more code in order to change passwords for all the users and all of the systems. The first issue was to be able to go through the entire password file and generate a new encrypted password for each user. It was decided to come up with a master passwd file that contained all of the users for any machine in the system. That is some users had accounts on all of the machines, other users might only have an account on one or two master. There is one system that contains that entire list of users, let’s call it MasterServer.  So the idea was to use the password file from MasterServer, strip out the first column of that password file and it will contain all of the users. Next generate the ascii of what is to be associated with each user. In other words, the new password the user will type in, not the encrypted password. The ascii type in word is generated from the following website:
To run this program you simply set the program length to 14 characters, set the password format to “base64” and set the number of passwords to 88, then click generate. The generated output is then associated with the column one entries from the passwd file.
generate-file is a script that merges the usernames with the ascii passwords in the following format:
username:ascii-password
It must also not generate any new passwords for users that are locked, daemons that don’t use passwords, or for the user ‘root’. In the case of the root accounts, each machine must have its own unique root password. The output of the generate-file script is password-file, it will be fed into the password-change-program.

The heart of the password-change-program is a small expect script, if expect is not installed, it must be installed along with its dependencies. For a Solaris 10 installation, these packages were installed. If the package’s name is indented, it is a requirement of its previous package:
expect-5.45-sol10-sparc-local

coreutils-8.11-sol10-sparc-local

tcl-8.5.10-sol10-sparc-local

        tk-8.5.10-sol10-sparc-local

                render-0.8-sol10-sparc-local

                xrender-0.8.3-sol10-sparc-local

                zlib-1.2.5-sol10-sparc-local

        gcc-3.4.6-sol10-sparc-local (and libgcc)

        libiconv-1.14-sol10-sparc-local

        libintl-3.4.0-sol10-sparc-local

gmp-4.2.1-sol10-sparc-local


All of these packages were downloaded from www.sunfreeware.com. That site is no longer around and has been replaced by unixpackages.com which you have to pay to download from. You can always download the sources and compile them yourself.
The password-change-program takes as its input password-file and uses the system’s passwd program to generate the encrypted passwords for all users. It is important to note that while the machine one is using to generate the new passwords, that system would have mixed results for someone attempting to log into it. It is impossible to determine what state the system is in. It may have already generated the new password for a particular user, before that user is notified, thus if he or she attempts a login at that time they will be denied access. Fortunately the program is being run on a management system that is primary used by the system administrators to manage other machines and users have been notified that the password change is in progress. The reason one would have mixed results is the encrypted field in the /etc/shadow file is being manipulated, and depending where in the process the password-change-program is, the user’s account may or may not have been updated. Once the password-change-program completes, one has a master list of encrypted passwords and new expiration dates.
The final piece of the puzzle is a script called pullshadow. It must be pointed out that this entire procedure  must be executed by a user that has access to all the machines the passwords are being updated on. Not only does that user need access, but also needs the ability to log into all remote machines without a password. This will be accomplished by using ssh and no password secure access. To create the no password access, if it is not already set up, perform the following steps:
Assuming the is being created for user everywhere-user with remote access to remote-machine.
ssh-keygen -t rsa
That will generate a key for user everywhere-user in the user’s home directory under .ssh
Now move that key to the user’s home directory on the remote machine that the user must access.

cat ~everywhere-user/.ssh/id_rsa.pub | \
ssh everywhere-user@remote-machine  "cat >> \
~everywhere-user/.ssh/authorized_keys"

The user will be prompted for a password. After this initial setup, a password will no longer be required. Now the pullshadow script will take advantage of this setup to retrieve each shadow file from all remote machines and update that shadow password file. Which machines are updated will be defined by a file named hosts, located in the current working directory. The hosts file in the current directory, is not to be confused with the /etc/hosts file. It has no bearing on that file, it only the name of the remote host. pullshadow uses the contents of host to determine which machines will be updated. pullshadow will copy the remote /etc/shadow file to the local machine, update it, and then copy it back. All users who were not locked out and that had a password will be updated. Each root account on the remote machine will have a unique password as well.


Tuesday, October 9, 2012

Recovering a file from a snapshot

We recently put together a little test bed of six workstations and 3 servers. All of this equipment is pretty old, but serves our purpose for testing things. I created a ZFS file system called home. Within home, I added a single file called junk which contained a single sentence. I then created a snapshot of "home", and finally restored that junk file:



cd /home

vi junk

zfs snaphot home@tuesday3

cd /home

rm junk

cd /home

cd .zfs

cd snapshot

cd Tuesday3

cp junk /home

Tuesday, October 4, 2011

Finally, Certified.

After several long months of study, I am finally an Oracle Certified Professional, specifically an Oracle Solaris 10 System Administrator.

Sunday, February 27, 2011

Solaris 10 Jumpstart

Our group inherited a bunch of SPARC workstations. It had been a while since I had tackled jumpstart, so with these extra machines, I decided to give it a go. First up was reloading one of the machines with Sol 10. Unfortunately we didn't have the passwords for any of these boxes, but I wanted to start fresh anyway. I took the defaults for the install, but selected ZFS for the export partition. I had a bit of a problem, since these machines will not be allowed on our network. The machine kept wanting to set up its interface. Finally I had to set it up as a standalone.

Over the weekend I picked up a wireless router to use it as a DHCP server. That did the trick, it allowed be to get the network access I would need to set up the jumpstart server and client enviroment.

I had previously downloaded the Solaris 10, update DVD. Many of the direction I found referred to the OS as being on cdroms, with the OS spread over a number of CDs. I took the DVD route. My jumpstart server has an ip address of 192.168.1.101, my client will be 192.168.1.102. 101 is called guajome-dome, while .102 will be called brownwrap.

1. I created a jumpstart directory: mkdir /export/jumpstart

2. Then went to the Tools directory of the install DVD:

cd /cdrom/cdrom0/Solaris_10/Tools

3. Ran the script to create the jumpstart server:

./setup_install_server /export/jumpstart

4. I then had to set up some services on the server, guajome-dome. I modiled /etc/inetd.conf and uncommented the tftp line to allow the client, brownwrap, to tftp to guajome-dome to grab the installation.

Then ran inetconv to add the service to the Service Management Facility (SFM).

Then enabled the service: svcadm enable tftpd

5. I then created a config directory: mkdir /export/jumpstart/config

and added two files to it sysidcfg and rules.

sysidcfg:

network_interface=primary {netmask=255.255.255.0}
security_policy=none
timezone=US/Mountain
system_locale=en_US
install_locale=en_US
name-service=none

rules:

hostname brownwrap - profile -

profile:

install_type initial_install
cluster SUNWCXall
partitionig explicit
filesystem
system_type standalone

Sunday, January 9, 2011

Swatch and Logwatch

I had wanted to do some log monitoring without reinventing the world, so I looked around for some log monitoring tools. I found logwatch, which was easy enough to download and install. Had a little problem with configuration, but since I was only interested in watching ssh logins I impleted a command to do just that.

In my looking around, I also found Swatch. Swatch is actually a PERL script. We had a very old very of PERL, so I downloaded and installed the latest from CPAN. I did this because Swatch kept asking for PERL modules which weren't in our version. Once I installed the latest version of PERL, I only needed an additional four modules which I installed. After that I was able to get Swatch up and running and used this command to start it:

/export/home/ramosg/localperl/bin/swatch --tail-file=/var/adm/messages --tail-args -f

Swatch also looks for a config file which I set up in my home directory:


.swatchrc
watchfor /Failed none for/
mail addresses=gregory.c.ramos

Tuesday, January 4, 2011

Security +

Well, I have taken a break from Linux for a while. New job, new state. One of my job requirements to meet DOD 8570 was to pass Security +. This was not a certification I would have gone after normally, but it was a job requirement, and it did get me back to studying again. So with that in mind, I have decided to pursue some Linux certs. The first up will be Linux+. I'll take that test and see how things go. If I pass it, it will get me not only Linux+, but LPI level 1, and Novell's Certified Linux Professional. So now, back to the books.

Thursday, August 5, 2010

Zpooling continued

Now that I have a working mirror again, I will 'repair' the failed disk:

# ls -l /media/Lexar/zfs-testbed/
total 3145729
-rwxrwxrwx 1 root root 512 2010-08-04 14:46 disk1
-rwxrwxrwx 1 root root 1073741824 2010-08-05 08:35 disk2
-rwxrwxrwx 1 root root 1073741824 2010-08-05 08:35 disk3
-rwxrwxrwx 1 root root 1073741824 2010-08-04 14:01 disk4

# rm /media/Lexar/zfs-testbed/disk1

# mkfile 1g /media/Lexar/zfs-testbed/disk1

# ls -l /media/Lexar/zfs-testbed/
total 4194304
-rwxrwxrwx 1 root root 1073741824 2010-08-05 08:48 disk1
-rwxrwxrwx 1 root root 1073741824 2010-08-05 08:45 disk2
-rwxrwxrwx 1 root root 1073741824 2010-08-05 08:45 disk3
-rwxrwxrwx 1 root root 1073741824 2010-08-04 14:01 disk4
#

Now time to add in the two 'spare disks' to the mirror:

# zpool add clifford mirror /media/Lexar/zfs-testbed/disk1 /media/Lexar/zfs-testbed/disk4

I'll use a different command to take a look at the mirror:

# zpool iostat -v clifford
capacity operations bandwidth
pool used avail read write read write
---------------------------------- ----- ----- ----- ----- ----- -----
clifford 150K 1.98G 0 0 1 826
mirror 120K 1016M 0 0 1 823
/media/Lexar/zfs-testbed/disk2 - - 0 0 62 878
/media/Lexar/zfs-testbed/disk3 - - 0 0 41 878
mirror 29.5K 1016M 0 0 0 565
/media/Lexar/zfs-testbed/disk1 - - 0 0 319 31.4K
/media/Lexar/zfs-testbed/disk4 - - 0 0 319 31.4K
---------------------------------- ----- ----- ----- ----- ----- -----

#