finger Command in Linux
The finger
command provides detailed information about users currently logged into a Linux system and reveals additional details such as login time, idle time, and user-specific notes or projects.
Linux administrators can monitor user activity and manage accounts effectively using the comprehensive output of finger
command.
- Basic Syntax of finger command:
finger [options] [username]
Prerequisites to Use Linux Command finger
To start using finger command in Linux, your machine needs to meet all the below specifications:
- A Linux VPS running a compatible Linux distribution (e.g., Ubuntu, Debian, CentOS).
- A non-root user with
sudo
privileges. - Access to Terminal/Command line.
Practical Examples to Learn finger Command in Linux
As a Linux system administrator or someone who manages users, it’s crucial to be familiar with various Linux commands such as finger command.
- Debian/Ubuntu:
sudo apt-get install finger
- CentOS/RedHat:
sudo yum install finger
sudo dnf install finger
Now that the finger
command is installed, let’s go through this tutorial to explore how to execute finger
command in Linux with various options and the functionalities of this command with practical examples to enhance your command line experience.
1. Display Information of Currently Logged-in Users
One of the simplest uses of the finger
command in Linux is to display information about all the users currently logged into the system.
- Syntax:
finger
Output
Login Name TTY Idle Login Time Office
jdoe John Doe pts/0 10:34 Oct 10 09:30
mjane Mary Jane pts/1 Oct 10 09:45
The output will show a list of all logged-in users, including their login name, terminal, login time, and idle time. This is a quick way to get an overview of who is using the system.
2. Retrieve Information About a Specific User
You can use the finger
command in Linux followed by a username to get detailed information about that user.
This includes login name, real name, home directory, shell, mail status, and the user’s plan.
- Syntax:
finger username
- Example:
finger opera
Output
Login: opera Name: Opera
Directory: /home/opera Shell: /bin/bash
On since Oct 10 09:20 (11 minutes ago) on pts/2
No mail.
Plan: New Plan
The output shows the opera’s full name, its home directory, the shell it is using, its login time, and its plan if it exists.
3. Display User Information in Short Format
If you want to see the user’s information in a more compact format, use the -s
option.
This option organizes the data in a concise, tabular form, making it easy to scan through the information.
- Syntax:
finger -s username
- Example:
finger -s opera
Output
Login Name TTY Idle Login Time Office
opera Opera pts/2 Oct 10 09:20
This short format gives essential details like the user’s login name, their terminal (TTY), idle time, and when they logged in.
4. Display Detailed Information Without .plan and .project Files
By default, the finger
command in Linux shows the contents of the .plan
and .project
files located in a user’s home directory.
If you prefer not to display these, you can use the -p
option, which suppresses this information.
- Syntax:
finger -p username
- Example:
finger -p opera
Output
Login: opera Name: Opera
Directory: /home/opera Shell: /bin/bash
On since Oct 10 09:20 (11 minutes ago) on pts/2
No mail.
As you see, the output omits the plan and project details.
5. Get Idle Status and Login Details of a User
If you’re managing system resources, knowing how long a user has been idle can be useful.
The finger
command in Linux can show the idle status along with other login details.
- Syntax:
finger -s username
- Example:
finger -s opera
Output
Login Name TTY Idle Login Time Office
opera Opera pts/2 10:45 Oct 10 09:20
As you see, in this example, Opera has been idle for 10 minutes and 45 seconds. This information is useful for monitoring user activity.
6. View User’s Plan and Project Information
Users can create a .plan
and .project
file in their home directory, which can be displayed using the finger
command.
The .plan
file typically contains notes about the user’s current tasks, while the .project
file can describe their ongoing projects.
- To create a plan for the user, use the following commands:
echo "Working on Linux project" > ~/.plan
echo "Linux System Optimization" > ~/.project
Then, retrieve the user’s plan and project information using the finger
command:
finger username
- Example:
finger opera
Output
Login: opera Name: Opera
Directory: /home/opera Shell: /bin/bash
On since Oct 10 09:20 (11 minutes ago) on pts/2
No mail.
Plan: Working on Linux project
Project: Linux System Optimization
This feature is helpful for system administrators or users collaborating in a project environment.
7. Prevent Matching the Full Name of a User
If you want to ensure that the finger
command in Linux only matches usernames and not full names, use the -m
option.
This is useful in situations where there might be ambiguity between usernames and full names.
- Syntax:
finger -m username
- Example:
finger -m opera
Output
finger: parker: no such user.
8. Create a Custom PGP Key for the User
You can also use the finger
command in Linux to display a user’s PGP key, which is stored in the .pgpkey
file in the home directory.
- Example:
cat > ~/.pgpkey
Once the file is created, the finger command will display its contents, making it a useful tool for showing public key information.
9. Display Information in Long Format
For a more detailed view, including additional system information like mail and login times, use the -l
option to display the user’s information in long format.
- Syntax:
finger -l username
- Example:
finger -l opera
Output
Login: opera Name: Opera
Directory: /home/opera Shell: /bin/bash
On since Oct 10 09:20 (1 hour 30 minutes ago) on pts/2
Mail last read Sun Oct 1 14:32 2023 (3 days ago)
Plan: Working on kernel development.
The -l
option provides additional information, including the exact login time, when mail was last read, and user plans or projects if available.
This can be especially useful for system administrators who need detailed user data.
Finger Command Options
At a glance, let’s review the common options for the finger command, including the syntax, description, and practical examples for each option.
Option | Description | Syntax | Example |
---|---|---|---|
No Option | Displays information about all currently logged-in users. | finger | finger |
-s | Displays information in a short (concise) format with columns. | finger -s | finger -s Ashley |
-p | Suppresses the display of the contents of the .plan , .project , and .pgpkey files. | finger -p | finger -p Ashley |
-l | Displays user information in long format with detailed system data. | finger -l | finger -l Ashley |
-m | Prevents finger from searching for matches in full names; only looks for exact username matches. | finger -m | finger -m Ashley |
username | Displays detailed information about the specified user (login name, home directory, etc.). | finger | finger Ashley |
Full Name | Displays user information by matching their full name instead of just the username. | finger | finger "Ashley" |
Custom Files | Shows information from user’s .plan , .project , and .pgpkey files. | finger | echo "New Plan" > ~/.plan; finger Ashley |
What is “no such user” error when using finger with a username?
This error typically means that the username you entered doesn’t exist on the system, or you may have misspelled it.
Double-check the username and ensure that you are entering the exact username as it appears on the system.
If you want to avoid this error for partial matches (like matching full names), avoid using the -m
option, which only looks for exact username matches.
Example:
finger -m Ashley # Will only match the username "Ashley"
Use:
finger Ashley
Why does finger not show the .plan or .project file information for a user?
If the .plan
or .project
files are not displayed, it could be for several reasons:
- The user does not have these files created in their home directory.
- The files may not have the correct permissions to be readable.
To create a .plan
or .project
file, the user can run:
echo "My Plan" > ~/.plan
echo "My Project" > ~/.project
Run the command below to ensure the files are readable:
chmod 644 ~/.plan ~/.project
Then, to see the plan and project details, run:
finger <username>
How to stop finger from showing my .plan, .project, or .pgpkey file information to other users?
If you don’t want your .plan
, .project
, or .pgpkey
to be displayed, you can remove read permissions for others:
Run the command below to hide the files from being viewed by others:
chmod 600 ~/.plan ~/.project ~/.pgpkey
How to troubleshoot the” finger Command Not Found” error?
This error means the finger package is not installed on your system. Install Linux command finger
using the below commands:
sudo apt install finger # For Ubuntu/Debian
sudo yum install finger # For CentOS/RedHat
What are finger command security considerations?
Since the finger
command in Linux can expose details such as user directories, login times, and custom notes, it’s recommended to disable the finger service on public-facing systems or restrict its usage to mitigate security risks.
To disable the finger
service on your machine, run:
sudo systemctl disable finger
Conclusion
From checking logged-in users to displaying user plans and projects, the finger
command in Linux has a wide range of practical applications for system administrators.
The examples in this guide explain how to effectively use different options of the finger command, helping you to retrieve specific user details, monitor activity, and manage resources efficiently.
Understanding and utilizing finger
command in Linux is crucial for maintaining system security, tracking user sessions, and optimizing overall system management.