Home > Articles > Operating Systems, Server > Linux/UNIX/Open Source

Getting onto the Unix System and Using the Command Line

In this chapter from Unix in 24 Hours, Sams Teach Yourself: Covers OS X, Linux, and Solaris, 5th Edition, learn how to log in to and log out of the system, change your password with the passwd command, choose a memorable and secure password, find out who the computer thinks you are, find out who else is on the system, find out what everyone is doing on the system, and check the current date and time.
This chapter is from the book

In this second Unix lesson, it’s time for you to log in to the system and try some commands. This hour focuses on learning the basics of interacting with your Unix machine.

This hour introduces many commands, so it’s very important that you have a Unix system available on which you can work through all the examples. Most examples have been taken from a PC running Solaris 11, a variant of Unix System V Release 4, and have been double-checked on both a BSD-based system and a Mac OS X command line. Any variance between the three is noted. If you have a Unix system available, odds are good that it’s based on either AT&T System V or Berkeley Unix.

Beginning Your Session

Before you can start interacting with the Unix command shell of your choice, you need to learn how to log in to your account. The good news is that it’s easy! Let’s have a look.

Task 2.1: Logging In to and Out of the System

Because Unix is a multiuser system, user authentication is always enforced: You always need to provide credentials (generally a username and a password) to the system so that it knows who you are. Some modern user-friendly flavors of Unix (such as Mac OS X) allow you to bypass this requirement by always booting into a single user’s desktop session, but this is just a convenience feature; under the hood, all Unix flavors are the same, and all require that you authenticate yourself at some stage of the process.

Old-school hardware terminals do still exist, or you might choose to boot a Linux or FreeBSD box directly to the textual console; but if you’re new to Unix, you’ll most likely need an application known as a terminal to access the command line. Most graphical operating systems include one. I use the Terminal app included with Mac OS X (in the Utilities folder) whether I’m accessing my local system or just opening an environment in which to connect to a remote system via ssh.

If you need to actually log in, the first thing you’ll see on the screen will look something like this:

GNU/Linux ado.aplonis.net 5:38pm on Tue, 8 Jul 2014
login:

The first line of this challenge prompt indicates what variant of Unix the system is running (GNU/Linux in this case), the hostname of the computer system, and the current time and date. The second line asks for your login, also known as your username or account name.

  1. Know your account name. It would be nice if computers could keep track of users by simply using full names so that I could enter Dave Taylor at the login prompt. Alas, like the Internal Revenue Service, the Department of Motor Vehicles, and many other agencies, Unix does not use names but instead assigns each user a unique identifier. This identifier, called an account name, has eight characters or fewer and is usually based on the user’s first or last name, although it can be any combination of letters and numbers. I have two account names, or logins, on the systems I use: taylor and, on another machine where someone already had that account name, d1taylor.
  2. Know your password. Perhaps your account name is on a piece of paper with your initial password, both assigned by the Unix system administrator. If you do not have this information, you need to track it down before you can go further. Some accounts might not have an initial password; in that case, you won’t have to enter one the first time you log in to the system. If that’s the case, create a password for your own security. In a few minutes, you will learn how you can give yourself the password of your choice by using the Unix command passwd.

    Note that a lot of systems are accessible only through the ssh function, and so a common way to connect to a modern system is to open up a local terminal app on your Mac or PC and type in something like:

    $ ssh taylor@intuitive.com

    where taylor is the account name and intuitive.com is the name of the remote host. If that’s how you need to access your Unix system remotely, it’s actually easier than using the login/password sequence; you just need to make extra sure that you type in everything exactly as prompted.

  3. At the login prompt, enter your account name if needed:

    login: taylor
    Password:

    Be particularly careful to use exactly what your administrator tells you to use (for example, the accounts taylor, Taylor, and TAYLOR are all different to Unix). After you’ve entered your account name, the system moves the cursor to the next line and prompts you for your password. If you’re using the ssh sequence, then the prompt will include your account name, as shown here:

    taylor@intuitive.com's password:

    Either way, when you enter your password, the system won’t echo it (that is, won’t display it) on the screen. That’s okay. Lack of an echo doesn’t mean anything is broken; instead, this is a security measure to ensure that even if people are looking over your shoulder, they can’t learn your secret password by watching your screen. Be certain to type your password correctly because you won’t see what you’ve typed and have a chance to correct it.

  4. After you’ve successfully entered your account name and password, you are shown some information about the system, some news for users, perhaps a fortune, and an indication of whether you have electronic mail. The specifics will vary, but here’s an example of what I see when I log in to my account:

    login: taylor
    Password:
    Last login: Thu Jul 7 17:00:23 on ttyAe
    You have mail.
    $

    Your system might be configured so that you have a slightly different prompt here. The possibilities include a % for the C shell, your current location in the file system, the current time, the command-index number (which you’ll learn about when you learn how to teach the Unix command-line interpreter to adapt to your work style rather than vice versa), and the name of the computer system itself. Here are some examples:

    [/users/taylor] :
    (mentor) 33 :
    taylor@mentor %

    Your prompt might not look exactly like any of these, but you know you’re looking at a prompt because it’s at the beginning of the line on which your cursor sits, and it reappears each time you’ve completed working with any Unix program. That’s how you know the program has completed its task.

  5. At this point, you’re ready to enter your first Unix command, exit, to sign off from the computer system. Try it. On my system, entering exit shuts down all my programs and quits the terminal app. On other systems, it returns you to the login prompt. Many Unix systems offer a pithy quote as you leave, too.

    % exit
    He who hesitates is lost.
    login:
  6. If you have a direct connection to the computer because you’re using a shared system in a computer center, library, or similar, odds are very good that logging out causes the system to prompt for another account name, enabling the next person to use the system. If you manually connected to the system via the Internet, you probably will see something more like the following example. After being disconnected from the remote system, you’ll then be able to safely shut down your local computer:

    % exit
    Did you lose your keys again?
    
    Connection to 154.23.11.140 closed.

At this point, you’ve stepped through the toughest parts of getting started with Unix. You have an account, know the password, have logged in to the system, and have entered a simple command telling the computer what you want to do, and the computer has done it!

Task 2.2: Changing Passwords with passwd

Having logged in to a Unix system, you can clearly see that many differences exist between Unix and a PC or Macintosh personal computer. Certainly the style of interaction is different. With Unix command lines, the keyboard becomes the exclusive method of instructing the computer what to do, and the mouse sits idle. One of the greatest differences is that Unix is a multiuser system, as you learned in the preceding hour. As you learn more about Unix, you’ll find that this characteristic has an impact on various tasks and commands. The next Unix command you’ll learn about is one that exists because of the multiuser nature of Unix: passwd.

With the passwd command, you can change the password associated with your individual account name. As with your personal identification number (PIN) for automated-teller machines, the value of your password is directly related to how secret it remains.

  1. Consider what happens when I use the passwd command to change the password associated with my account:

    % passwd
    Changing password for taylor.
    Old password:
    New passwd:
    Retype new passwd:
    %
  2. Notice that I never received any visual confirmation that the password I actually entered was the same as the password I thought I entered. This is not as dangerous as it seems, though, because if I had made any typographical errors, the password I entered the second time (when the system said Retype new passwd:) wouldn’t have matched the first. In a no-match situation, the system would have warned me that the information I supplied was inconsistent:

    % passwd
    Changing password for taylor.
    Old password:
    New passwd:
    Retype new passwd:
    Mismatch - password unchanged.
    %
  3. Smart systems will complain if you pick a really bad password or one that’s just obviously too short. I tried cat on my Oracle Solaris system, and the passwd command complained:

    passwd: Password too short - must be at least 6 characters.

    Oops. In the next section you’ll learn about how to pick good, hard-to-guess but easy-to-remember passwords.

After you change the password, don’t forget it. Resetting it to a known value if you don’t know the current password requires the assistance of a system administrator or other operator. Using a trick to remember your password can be a Catch-22, though: You don’t want to write down the password because that reduces its secrecy and you don’t want to make it too easy to remember because someone else can then guess it, but you don’t want to forget it, because that can be all sorts of hassle. You want to be sure that you pick a good password, too, as described in Task 2.3.

Task 2.3: Picking a Secure Password

If you’re an aficionado of old movies, you are familiar with the thrillers in which the hoods break into an office and spin the dial on the safe a few times, snicker a bit about how the boss shouldn’t have chosen his daughter’s birthday as the combination, and crank open the safe. (If you’re really familiar with the genre, you recall films in which the criminals rifle the desk drawers and find the combination of the safe taped to the underside of a drawer as a fail-safe, or a failed safe, as the case may be. Hitchcock’s great film Marnie has just such a scene.) The moral is that even the best secret password is useful only if you keep it secret.

For computers, security is tougher because a fast computer system can test all the words in an English dictionary against your account password faster than you can say “don’t hack me, bro.” If your password is kitten or, worse yet, your account name, any semicompetent bad guy could be in your account and messing with your files in no time. This is called a dictionary attack.

Most modern Unix systems have some heuristics, or smarts, built in to the passwd command; the heuristics check to determine whether what you’ve entered is reasonably secure.

The tests performed typically answer these questions:

  • Is the proposed password at least six characters long? (A longer password is more secure.)
  • Does it have both digits and letters? (A mix of both is best.)
  • Does it mix upper- and lowercase letters? (A mix is best.)
  • Does it include at least one punctuation character? (adding a %, !, @, or even . is best)
  • Is it in the online dictionary? (You should avoid common words.)
  • Is it a name or word associated with the account? (Dave would be a bad password for my account taylor because my full name on the system is Dave Taylor).

Some versions of the passwd program are more sophisticated, and some less, but generally the following are good guidelines for picking a secure password:

  1. An easy way to choose memorable and secure passwords is to think of them as small sentences rather than as a single word with some characters surrounding it. If you’re a fan of Alexander Dumas and The Three Musketeers, then “All for one and one for all!” is a familiar cry, but it’s also the basis for a couple of great passwords. Easily remembered derivations might be the punnish awl4ONE? or a41&14A!.
  2. If you’ve been in the service, you might have the old U.S. Army jingle stuck in your head: “Be All You Can Be.” Try thinking of that phrase as a series of abbreviations and letters: ballucanb. Turn that into a good password with a few additional tweaks: 4ballu@canb. You might have a self-referential password: account4me or MySekrit would work. If you’re ex-Vice President Dan Quayle, 1Potatoe could be a memorable choice. (potatoe by itself wouldn’t be particularly secure because it lacks digits and lacks uppercase letters and because it’s a simple variation on a word in the online dictionary.)
  3. Another way to choose passwords is to find acronyms that have special meaning to you. Don’t choose simple ones. Remember, short ones aren’t going to be secure. But if you have always heard that “Real programmers don’t eat quiche!” then Rpdeq! could be a complex password that you’ll easily remember.
  4. Many systems you use every day require numeric passwords to verify your identity, including the automated-teller machine (with its PIN), government agencies (with the Social Security number), and the Department of Motor Vehicles (your driver’s license number or vehicle license). Each of these actually is a poor Unix password because it’s too easy for someone to find out your license number or Social Security number. And a series of nothing but numbers is a terrible password anyway!

Why be so paranoid? For a small Unix system that will sit on your desk and won’t have any other users, a high level of concern for security is, to be honest, unnecessary. As with driving a car, though, it’s never too early to learn good habits. Any system that has Internet access means that it’s probably accessible from the Internet, too, and that means it’s at risk of hackers trying to break in, a target for delinquents who relish the intellectual challenge of breaking into an account and then altering and destroying files and programs purely for amusement.

The best way to avoid trouble is to develop good security habits now, when you’re first learning about Unix. Learn how to recognize what makes a good, secure password, pick one for your account, and keep it a secret. Don’t write it down, or, if you must, keep that note secure too and notify your admin if it gets lost. A little prevention can be a lot easier than mopping up after a security breech.

With that in mind, log in again to your Unix system and try changing your password. First, change it to easy and see whether the program warns you that easy is too short or otherwise a poor choice. Then try entering two different secret passwords to see whether the program notices the difference. Finally, pick a good password, using the preceding guidelines and suggestions, and change your account password to be more secure.

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020