So come on, let's go through and find ourselves a command line,
a command line where we can get some practice in listing our users.
So, of course, we can take a look at the /etc/passwd file.
We can go through and visit the command getent and the file
nsswitch.conf acting in our back end.
And we can look at using our filtering commands,
so we can filter using the cut command or with the awk command.
So once you're ready,
let's find ourselves that command line on our AlmaLinux 8 system.
And a big warm welcome to this demonstration,
our first demonstration of our user management.
And we're on the glorious command line of AlmaLinux 8.
As always,
I do hope you're following along on your own systems because this
is where your real learning is going to begin.
And we're going to begin by using the cat command,
cat for concatenate, as we go through and open up our /etc/passwd file.
And here we can see then all of our local users,
user accounts that are stored locally on each of our systems,
desktops or servers.
Now, of course, we've got a heap of information here,
and then you might be a little bit curious about each one of these fields.
And you should be curious, that then leads to your learning.
We can open up the man page, so man 5 and passwd.
Okay, look, we don't have a manual entry for passwd.
Section 5 is just our configuration file entries.
We've got a brand‑new virtual machine here,
and we might find that the scheduled task to update
the man database hasn't yet run, so we can always try updating that.
We don't want to give up just yet, do we?
So this is not difficult.
It's just a matter of going through,
upgrading our privileges or elevating our privileges
and running the mandb command.
We can go back, and we've still not got any luck,
but we are not going to give up.
We're going to persevere.
It just means that the man pages for this aren't installed.
It's not surprising. This is a virtual machine, and to keep the image small,
they install the minimum amount of packages. So I can go through using the
sudo command, and in RedHat‑based systems, the software installer is yum and
install ‑ y, so it doesn't prompt me and then going through, and it's just a
package called man‑pages. We can allow this to run through and, of course,
then it's added in some of the very basic system manual pages, which then
should allow me, I'm just going to double check by updating the man
database, I don't want to fail again, but keeping my fingers crossed now our
man 5 passwd, it was worth persisting and waiting for. So as we then go
through and scroll through, we can explain then some of these fields. We can
see the field names and their descriptions.
So we've got our username, the password,
the password is not normally stored here.
It's normally an * indicating that the password is stored in the shadow file,
the user ID, the group ID, the GECOS, or often known as the comments field,
the home directory, and the user's default shell.
So I'm going to leave this for you to read for some light, bedtime reading.
But we're going to continue taking a look at listing our users. By
taking a look only at the etc and passwd file, we're literally looking
at just our local users. Now that's all I have on this system, but
using the getent, the get entire passwd, we're actually being directed
to all of our user sources.
So the local password file plus any identity vault that we might
have, Active Directory or open LDAP. We can go through as well
as search for a particular user.
So I'm logged in as a Vagrant user, and we can list then
the properties for the Vagrant user.
So we can see then the nice little command that we've getent
passwd and vagrant, but we can perhaps get a little bit more
specific by filtering on our columns.
Using the cut command, we can go through and display field 1 and field 3 where
the delimiter is a colon and we get then vagrant : 1000.
But if you don't want the colon, then we can upgrade to the
big brother of cut and use the awk command.
So as I say, using the command awk, or awk, we can go through
and specify our field separator using the ‑F.
Using our quotes, we can go through and open up what we want to
issue, and we want to search for a string vagrant.
A string is placed inside of our forward slashes, but with just line
numbers, we can go through and put the numbers without then specifying
the /. The brace brackets enclose our command.
We want to go through and print and the same as before, we're going to print $1
field 1, but we don't need to have our default separator.
We can separate them with a space. So we've got $1 space $3. We can
close off then our statement with closing our right bracket, and we can
then go through and close off our quotes.
But looking at this, we've got single quotes all of the way through.
Opening our quotes inside of our brace brackets is going to cause us
problems. So it doesn't really matter the quotes that we use,
especially inside of our command.
So I'm just going to replace them with double quotes
for the space that we want to print.
Of course, we need to specify the file that we want to search.
So it's going to be our /etc/passwd, and you can see we've got
that same information, but this time we can choose the separator
that we want to be between vagrant and 1000 and, we've got the
space instead of a colon.
So awk is just that little bit more flexible.
A finishing point is by going through and searching for
the string passwd from inside of the etc/nsswitch.conf,
our name service switch.conf.
This is used by the getent command so we can interrogate
where to look. The uncommented line for our password is
saying that when we use getent password,
we first look in our security services subsystem,
and that's a daemon.
It's not being used at the moment,
but we'll look at it in a later module where we set up,
then LDAP access.
Second to that, we then go through and search our local files, so
that's going to be our etc and passwd file.
But we can also go through and look for any system d
based users as our third attempt.
But this is what we're using when we issue the getent command.
So hopefully this has lifted the lid a little bit about our user storage and where our users are located.