- 11 Ways to Find User Account Info and Login Details in Linux
- 1. id Command
- 2. groups Command
- 3. finger Command
- 4. getent Command
- 5. grep Command
- 6. lslogins Command
- 7. users Command
- 8. who Command
- 9. w Command
- 10. last or lastb commands
- 11. lastlog Command
- If You Appreciate What We Do Here On TecMint, You Should Consider:
- 14 Useful Linux Networking Commands
- ip link
- ip address
- ip route
- iPerf
- traceroute
- tcpdump
- netstat
- scp and sftp
- Ifconfig
- telnet
- nslookup
- Summary
- Network configuration
- Contents
- Check the connection
- Network management
- net-tools
- iproute2
- Network interfaces
- Listing network interfaces
- Enabling and disabling network interfaces
- Static or dynamic IP address?
- Static IP address
- IP addresses
- Routing table
- Servers
- Network managers
- Set the hostname
- Local hostname resolution
- Local network hostname resolution
- Tips and tricks
- Change interface name
- Revert to traditional interface names
- Set device MTU and queue length
- Bonding or LAG
- IP address aliasing
- Example
- Promiscuous mode
- Investigate sockets
- Troubleshooting
- The TCP window scaling problem
- How to diagnose the problem
- Ways of fixing it
- More about it
- Connected second PC unable to use bridged LAN
11 Ways to Find User Account Info and Login Details in Linux
This article will show you eleven useful ways to find the information about users on a Linux system. Here we’ll describe commands to get a user’s account details, show login details as well as what users are doing on the system.
If you want to add users in Linux, use the useradd utility, and to modify or change any attributes of a already created user account, use the usermod via the command line as explained in the following guides:
We’ll start by looking at commands to find a user’s account information, then proceed to explain commands to view login details.
1. id Command
id is a simple command line utility for displaying a real and effective user and group IDs as follows.
2. groups Command
groups command is used to show all the groups a user belongs to like this.
3. finger Command
finger command is used to search information about a user on Linux. It doesn’t come per-installed on many Linux systems.
To install it on your system, run this command on the terminal.
It shows a user’s real name; home directory; shell; login: name, time; and so much more as below.
4. getent Command
getent is a command line utility for fetching entries from Name Service Switch (NSS) libraries from a specific system database.
To get a user’s account details, use the passwd database and the username as follows.
5. grep Command
grep command is a powerful pattern searching tool available on most if not all Linus systems. You can use it to find information about a specific user from the system accounts file: /etc/passwd as shown below.
6. lslogins Command
lslogins command shows information about known users in the system, the -u flag only displays user accounts.
7. users Command
users command shows the usernames of all users currently logged on the system like so.
8. who Command
who command is used to display users who are logged on the system, including the terminals they are connecting from.
9. w Command
w command shows all users who are logged on the system and what they are doing.
10. last or lastb commands
last/lastb commands displays a list of last logged in users on the system.
To show all the users who were present at a specified time, use the -p option as follows.
11. lastlog Command
lastlog command is used to find the details of a recent login of all users or of a given user as follows.
That’s it! If you know any other command-line trick or command to view user account details do share with us.
You’ll find these related article so useful:
In this article, we’ve explained various ways to find information about users and login details on a Linux system. You can ask any questions or share your thoughts via the feedback form below.
If You Appreciate What We Do Here On TecMint, You Should Consider:
TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
We are thankful for your never ending support.
Источник
14 Useful Linux Networking Commands
Geekflare is supported by our audience. We may earn affiliate commissions from buying links on this site.
Configuring, monitoring, and securing networks form an essential part of a Sysadmin’s job. When it comes to managing Linux networks, there are many commands and utilities available.
At times networked systems fail. You as an administrator are required to diagnose and resolve issues. Monitoring helps in detecting problems and fixing them before things get out of hand. Monitoring for security and performance also forms an essential part of an admin’s activities.
Here we discuss some commonly used commands to manage Linux networks.
The iproute2 package includes the IP command which is used for network and routing configuration. This replaces the traditional ifconfig and route commands.
ip takes a second argument that specifies the object on which you wish to execute a command and an action like add, delete, or show.
ip link
ip link is for configuring, adding, and deleting network interfaces. Use ip link show command to display all network interfaces on the system :
You can see the man page for ip link with:
ip address
Use ip address command to display addresses, bind new address or delete old ones. The man page ip address command is named as ip-address.
For example, the following command shows the IP address assigned to the network interface enp0s8:
ip route
Use the IP route to print or display the routing table. The following command displays the contents of the routing table:
While Nmap had been used in many movies, The Matrix Reloaded ( Wikipedia , IMDB , Amazon ) turned Nmap into a movie star!.
Nmap (“Network Mapper”) is a powerful utility used for network discovery, security auditing, and administration. Many system admins use it to determine which of their systems are online, and also for OS detection and service detection.
The default Nmap scan shows the ports, their state (open/closed), and protocols. It sends a packet to 1000 most common ports and checks for the response.
To check which hosts on your network are up:
Use -O flag to identify which operating system a host is running.
A word of caution: Nobody appreciates their systems being scanned over the internet. So before you do so, seek permission.
You can also use Nmap on Windows, check out this installation guide.
Use ping to see if a host is alive. This super simple command helps you check the status of a host or a network segment. Ping command sends an ICMP ECHO_REQUEST packet to the target host and waits to see if it replies.
However, some hosts block ICMP echo requests with a firewall. Some sites on the internet may also do the same.
By default, ping runs in an infinite loop. To send a defined number of packets, use -c flag.
With -o flag ping exits successfully after receiving one reply packet.
You can use -n flag to avoid reverse DNS lookups. The ICMP sequence number is particularly important. A Break in sequence numbers indicates lost packets.
A failed ping could be due to
- network failure
- host being not alive
- firewall blocking ICMP ECHO requests
You can also perform an online ping test to check the connectivity from different parts of the world.
iPerf
While ping verifies the availability of a host, iPerf helps analyze and measure network performance between two hosts. With iPerf, you open a connection between two hosts and send some data. iPerf then shows the bandwidth available between the two hosts.
You can install an iPerf using your distribution package manager. For example on Ubuntu-based distributions you can install like this:
Once you have installed iPerf on both the machines, start the iPerf server on one of them. The following example starts the iPerf server on a host with IP address 10.0.0.51.
On the second machine start iPerf with the -c flag. This connects with the server and sends some data.
iPerf returns with the bandwidth results in a few seconds.
traceroute
If ping shows missing packets, you should use traceroute to see what route the packets are taking. Traceroute shows the sequence of gateways through which the packets travel to reach their destination. For example, traceroute from my machine to google.com shows the following:
Line 4 in this output shows a * in the round trip times. This indicates no response was received. This can be due to many reasons – as the traceroute ICMP packets are low-priority, these may be dropped by a router. Or there could be simply congestion. If you see a * in all the time fields for a given gateway, then possibly the gateway is down.
Many web-based route tracing tools allow you to do a reverse traceroute, that is, from a website to your host. You can check these at traceroute.org or Geekflare Traceroute.
tcpdump
tcpdump is a packet sniffing tool and can be of great help when resolving network issues. It listens to the network traffic and prints packet information based on the criteria you define.
For example, you can examine all packets sent to or from a particular host, Ubuntu18 in this example:
By default, tcpdump resolves IP addresses to hostnames. Use -n flag, if you do not want tcpdump to perform name lookups.
tcpdump output prints one line for each packet. Use -c flag to limit output, 5 in the example above.
tcpdump is useful for solving network problems and also identifying potential problems. It is a good idea to run a tcpdump on your network occasionally to verify everything is in order.
netstat
Netstat command is used to examine network connections, routing tables, and various network settings and statistics.
Use -i flag to list the network interfaces on your system.
Here is an example:
Using -r flag will display the routing table. This shows the path configured for sending network packets.
An asterisk in the last two lines indicates that no gateway is required to send packets to any host on these networks. This host is directly connected to the networks 10.0.0.0 and 10.0.2.0.
In the first line, the destination is the default, which means any packet destined for a network not listed in this table is handled by the router 10.0.2,2.
netstat command without any options displays a list of open sockets. Use -l flag to show only listening sockets, which by default, are not shown. You can use -a flag to show listening and non-listening sockets. Here is an example:
More Netstat command example here
Linux installations have a lot of services running by default. These should be disabled or preferably removed, as this helps in reducing the attack surface. You can see what services are running with the netstat command. While netstat is still available, most Linux distributions are transitioning to ss command.
use ss command with -t and -a flags to list all TCP sockets. This displays both listening and non-listening sockets.
To display only TCP connections with state established:
ssh enables you to connect securely with remote hosts over the internet. Earlier rlogin and telnet were used to connect to and administer remote hosts. However, both suffer from a fundamental flaw, that is, they send all information including login names and passwords in cleartext.
ssh enables secure communication over the internet with the following two features :
- It confirms that the remote host is, who it says it is.
- It encrypts all communication between the hosts.
To connect to a remote host you need to have an OpenSSH server running on the remote host. You can install it using your distribution package manager. For example on Ubuntu you can install it like this:
Here is an example showing how you can connect to the remote host 10.0.0.50 using the ssh command:
You get a message saying that the authenticity of the host 10.0.0.50 cannot be established, this is because it’s the first time a connection is being made with 10.0.0.50 (server) and the ssh client has never seen this remote host before. Enter yes to continue connecting. Once the connection has been established, you are prompted for a password:
After you enter the correct password, you are logged into the remote host.
You can exit this remote shell with the exit command.
Also, you can easily execute a single command on the remote host using ssh. For example, to run df -h on the remote host:
scp and sftp
scp (secure copy) is very similar to cp command for copying files, with an addition – you can include remote hostnames in the source or destination pathnames. The hostname and the directory path are separated by a colon. This enables you to copy files securely over the network in an encrypted form. The following command copies a.txt from the local machine to 10.0.0.50 :
sftp (secure ftp) is also a file copy program similar to ftp . However, it uses an SSH encrypted tunnel to copy files, instead of sending everything in cleartext. Also, you do not need an FTP server running on the remote host. You only need an ssh server. Here is an example session:
Ifconfig
Mostly we use ifconfig command to check the IP address assigned to the system.
dig (Domain Information Groper) is a flexible tool for interrogating DNS name servers.
It performs DNS lookups and displays the answers that are returned from the name servers.
telnet
telnet connect destination’s host and port via a telnet protocol if a connection establishes means connectivity between two hosts is working fine.
nslookup
nslookup is a program to query domain name servers and resolving IP.
Summary
Networking in Linux is a vast subject, with a large number of commands and utilities. In this article, we have discussed some commonly used commands which hopefully, will help you in managing and securing your network.
Источник
Network configuration
This article describes how to configure network connections on OSI layer 3 and above. Medium-specifics are handled in the /Ethernet and /Wireless subpages.
Contents
Check the connection
To troubleshoot a network connection, go through the following conditions and ensure that you meet them:
- Your network interface is listed and enabled. Otherwise, check the device driver – see /Ethernet#Device driver or /Wireless#Device driver.
- You are connected to the network. The cable is plugged in or you are connected to the wireless LAN.
- Your network interface has an IP address.
- Your routing table is correctly set up.
- You can ping a local IP address (e.g. your default gateway).
- You can ping a public IP address (e.g. 8.8.8.8 , which is a Google DNS server and is a convenient address to test with).
- Check if you can resolve domain names (e.g. archlinux.org ).
This article or section needs expansion.
ping is used to test if you can reach a host.
For every reply you receive, the ping utility will print a line like the above. For more information see the ping(8) manual. Note that computers can be configured not to respond to ICMP echo requests. [1]
If you receive no reply, this may be related to your default gateway or your Internet Service Provider (ISP). You can run a traceroute to further diagnose the route to the host.
Network management
To set up a network connection, go through the following steps:
- Ensure your network interface is listed and enabled.
- Connect to the network. Plug in the Ethernet cable or connect to the wireless LAN.
- Configure your network connection:
- static IP address
- dynamic IP address: use DHCP
net-tools
Arch Linux has deprecated net-tools in favor of iproute2 .[2]
Deprecated command | Replacement commands |
---|---|
arp | ip neighbor |
ifconfig | ip address, ip link |
netstat | ss |
route | ip route |
iproute2
iproute2 is a dependency of the base meta package and provides the ip(8) command-line interface, used to manage network interfaces, IP addresses and the routing table. Be aware that configuration made using ip will be lost after a reboot. For persistent configuration, you can use a network manager or automate ip commands using scripts and systemd units. Also note that ip commands can generally be abbreviated, for clarity they are however spelled out in this article.
Network interfaces
By default udev assigns names to your network interfaces using Predictable Network Interface Names, which prefixes interfaces names with en (wired/Ethernet), wl (wireless/WLAN), or ww (WWAN). See systemd.net-naming-scheme(7) .
Listing network interfaces
Both wired and wireless interface names can be found via ls /sys/class/net or ip link . Note that lo is the virtual loopback interface and not used in making network connections.
Wireless device names can also be retrieved using iw dev . See also /Wireless#Get the name of the interface.
If your network interface is not listed, make sure your device driver was loaded successfully. See /Ethernet#Device driver or /Wireless#Device driver.
Enabling and disabling network interfaces
Network interfaces can be enabled or disabled using ip link set interface up|down , see ip-link(8) .
To check the status of the interface eth0 :
The UP in
is what indicates the interface is up, not the later state DOWN .
Static or dynamic IP address?
This article or section needs language, wiki syntax or style improvements. See Help:Style for reference.
If you are using a Wi-FI or a router, for example, at home, you will most likely be using a dynamic IP address. The IP address is assigned by the Wi-Fi or router and it is what your computer should be configured to use. Or, if you are at home and your computer is connected to your ISP’s modem, for example, a cable modem, that will also be using a dynamic IP address. Dynamic IP addresses can change each time you turn your computer on. In a work environment you may have a static IP address or a dynamic IP address. At home you can configure your router to always assign your computer the same IP address in which case you are using a static IP address. When you are using a dynamic IP address you will need to use DHCP so that it can set up your network interface with the correct IP address. In addition to configuring your IP address, DHCP can also configure your routing (how to get from where you are to wherever on the network you are going) as well as your name servers, which convert the host name, for example, google.com, into its IP address, that number with dots in it.
Static IP address
A static IP address can be configured with most standard network managers and also dhcpcd.
To manually configure a static IP address, add an IP address as described in #IP addresses, set up your routing table and configure your DNS servers.
IP addresses
List IP addresses:
Add an IP address to an interface:
Note that:
- the address is given in CIDR notation to also supply a subnet mask
- + is a special symbol that makes ip derive the broadcast address from the IP address and the subnet mask
Delete an IP address from an interface:
Delete all addresses matching a criteria, e.g. of a specific interface:
Routing table
The routing table is used to determine if you can reach an IP address directly or what gateway (router) you should use. If no other route matches the IP address, the default gateway is used.
The routing table is managed using ip-route(8) .
PREFIX is either a CIDR notation or default for the default gateway.
List IPv4 routes:
List IPv6 routes:
A Dynamic Host Configuration Protocol (DHCP) server provides clients with a dynamic IP address, the subnet mask, the default gateway IP address and optionally also with DNS name servers.
To use DHCP you need a DHCP server in your network and a DHCP client:
Client | Package | Archiso | Note | Systemd units |
---|---|---|---|---|
dhcpcd | dhcpcd | Yes | DHCP, DHCPv6, ZeroConf, static IP | dhcpcd.service , dhcpcd@interface.service |
ISC dhclient | dhclient | Yes | DHCP, DHCPv6, BOOTP, static IP | dhclient@interface.service |
Servers
This article or section needs expansion.
Server | Package | IPv4 | IPv6 | GUI | Interfaces | Storage backend(s) | Note |
---|---|---|---|---|---|---|---|
dhcpd | dhcp | Yes | Yes | Glass-ISC-DHCP | ? | File | |
dnsmasq | dnsmasq | Yes | Yes | No | ? | File | Also DNS, PXE and TFTP |
Kea | kea | Yes | Yes | Kea-Anterius (Experimental) | REST, RADIUS and NETCONF | File, MySQL, PostgreSQL and Cassandra | Also DNS |
Network managers
A network manager lets you manage network connection settings in so called network profiles to facilitate switching networks.
Network manager | GUI | Archiso [3] | CLI tools | PPP support (e.g. 3G modem) | DHCP client | systemd units |
---|---|---|---|---|---|---|
ConnMan | 8 unofficial | No | connmanctl(1) | Yes (with ofono AUR ) | internal | connman.service |
netctl | 2 unofficial | No | netctl(1) , wifi-menu | Yes | dhcpcd or dhclient | netctl-ifplugd@interface.service , netctl-auto@interface.service |
NetworkManager | Yes | No | nmcli(1) , nmtui(1) | Yes | internal or dhclient | NetworkManager.service |
systemd-networkd | No | Yes ( base ) | networkctl(1) | No | internal | systemd-networkd.service , systemd-resolved.service |
Wicd | Yes | No | wicd-cli(8) , wicd-curses(8) | No | dhcpcd or dhclient | wicd.service |
Set the hostname
This article or section needs language, wiki syntax or style improvements. See Help:Style for reference.
A hostname is a unique name created to identify a machine on a network, configured in /etc/hostname —see hostname(5) and hostname(7) for details. The file can contain the system’s domain name, if any. To set the hostname, edit /etc/hostname to include a single line with myhostname :
To temporarily set the hostname (until reboot), use hostname(1) from inetutils :
To set the «pretty» hostname and other machine metadata, see machine-info(5) .
Local hostname resolution
This article or section needs expansion.
nss-myhostname(8) (an NSS module provided by systemd) provides local hostname resolution without having to edit /etc/hosts . It is enabled by default.
Some software may however still read /etc/hosts directly, see [4] [5] for examples. To prevent them from potentially breaking, hanging or otherwise delaying operation, make sure they can resolve the local hostname and localhost by configuring the hosts(5) file:
For a system with a permanent IP address, replace 127.0.1.1 with that permanent IP address. For a system with a fully qualified domain name, insert the fully qualified domain name before the hostname. For example:
As a result the system resolves to both entries:
Local network hostname resolution
To make your machine accessible in your LAN via its hostname you can:
- edit the /etc/hosts file for every device in your LAN, see hosts(5)
- set up a DNS server to resolve your hostname and make the LAN devices use it (e.g. via #DHCP)
- or the easy way: use a Zero-configuration networking service:
- Hostname resolution via Microsoft’s NetBIOS. Provided by Samba on Linux. It only requires the nmb.service . Computers running Windows, macOS, or Linux with nmb running, will be able to find your machine.
- Hostname resolution via mDNS. Provided by either nss_mdns with Avahi (see Avahi#Hostname resolution for setup details) or systemd-resolved. Computers running macOS, or Linux with Avahi or systemd-resolved running, will be able to find your machine. The older Win32 API does not support mDNS, which may prevent some older Windows applications from accessing your device.
Tips and tricks
Change interface name
You can change the device name by defining the name manually with an udev-rule. For example:
These rules will be applied automatically at boot.
A couple of things to note:
- To get the MAC address of each card, use this command: cat /sys/class/net/device_name/address
- Make sure to use the lower-case hex values in your udev rules. It does not like upper-case.
If the network card has a dynamic MAC, you can use DEVPATH , for example:
To get the DEVPATH of all currently-connected devices, see where the symlinks in /sys/class/net/ lead. For example:
The device path should match both the new and old device name, since the rule may be executed more than once on bootup. For example, in the second rule, «/devices/pci*/*1c.0/*/net/enp*» would be wrong since it will stop matching once the name is changed to en . Only the system-default rule will fire the second time around, causing the name to be changed back to e.g. enp1s0 .
If you are using a USB network device (e.g. Android phone tethering) that has a dynamic MAC address and you want to be able to use different USB ports, you could use a rule that matched depending on vendor and product ID instead:
To test your rules, they can be triggered directly from userspace, e.g. with udevadm —debug test /sys/class/net/* . Remember to first take down the interface you are trying to rename (e.g. ip link set enp1s0 down ).
Revert to traditional interface names
If you would prefer to retain traditional interface names such as eth0, Predictable Network Interface Names can be disabled by masking the udev rule:
Alternatively, add net.ifnames=0 to the kernel parameters.
Set device MTU and queue length
You can change the device MTU and queue length by defining manually with an udev-rule. For example:
mtu : Using a value larger than 1500 (so called jumbo frames) can significantly speed up your network transfers. Note that all network interfaces, including switches in the local network, must support the same MTU in order to use jumbo frames. For PPPoE, the MTU should not be larger than 1492. You can also set MTU via systemd.netdev(5) .
tx_queue_len : Small value for slower devices with a high latency like modem links and ISDN. High value is recommended for server connected over the high-speed internet connections that perform large data transfers.
Bonding or LAG
IP address aliasing
IP aliasing is the process of adding more than one IP address to a network interface. With this, one node on a network can have multiple connections to a network, each serving a different purpose. Typical uses are virtual hosting of Web and FTP servers, or reorganizing servers without having to update any other machines (this is especially useful for nameservers).
Example
To manually set an alias, for some NIC, use iproute2 to execute
To remove a given alias execute
Packets destined for a subnet will use the primary alias by default. If the destination IP is within a subnet of a secondary alias, then the source IP is set respectively. Consider the case where there is more than one NIC, the default routes can be listed with ip route .
Promiscuous mode
Toggling promiscuous mode will make a (wireless) NIC forward all traffic it receives to the OS for further processing. This is opposite to «normal mode» where a NIC will drop frames it is not intended to receive. It is most often used for advanced network troubleshooting and packet sniffing.
If you want to enable promiscuous mode on interface eth0 run enable promiscuous@eth0.service .
Investigate sockets
ss is a utility to investigate network ports and is part of the iproute2 package. It has a similar functionality to the deprecated netstat utility.
Common usage includes:
Display all TCP Sockets with service names:
Display all TCP Sockets with port numbers:
Display all UDP Sockets:
For more information see ss(8) .
Troubleshooting
The TCP window scaling problem
TCP packets contain a «window» value in their headers indicating how much data the other host may send in return. This value is represented with only 16 bits, hence the window size is at most 64KiB. TCP packets are cached for a while (they have to be reordered), and as memory is (or used to be) limited, one host could easily run out of it.
Back in 1992, as more and more memory became available, RFC 1323 was written to improve the situation: Window Scaling. The «window» value, provided in all packets, will be modified by a Scale Factor defined once, at the very beginning of the connection. That 8-bit Scale Factor allows the Window to be up to 32 times higher than the initial 64KiB.
It appears that some broken routers and firewalls on the Internet are rewriting the Scale Factor to 0 which causes misunderstandings between hosts. The Linux kernel 2.6.17 introduced a new calculation scheme generating higher Scale Factors, virtually making the aftermaths of the broken routers and firewalls more visible.
The resulting connection is at best very slow or broken.
How to diagnose the problem
First of all, let us make it clear: this problem is odd. In some cases, you will not be able to use TCP connections (HTTP, FTP, . ) at all and in others, you will be able to communicate with some hosts (very few).
When you have this problem, the output from dmesg is okay, logs are clean and ip addr will report normal status. and actually everything appears normal.
If you cannot browse any website, but you can ping some random hosts, chances are great that you are experiencing this problem: ping uses ICMP and is not affected by TCP problems.
You can try to use Wireshark. You might see successful UDP and ICMP communications but unsuccessful TCP communications (only to foreign hosts).
Ways of fixing it
To fix it the bad way, you can change the tcp_rmem value, on which Scale Factor calculation is based. Although it should work for most hosts, it is not guaranteed, especially for very distant ones.
Simply disable Window Scaling. Since Window Scaling is a nice TCP feature, it may be uncomfortable to disable it, especially if you cannot fix the broken router. There are several ways to disable Window Scaling, and it seems that the most bulletproof way (which will work with most kernels) is to add the following line to /etc/sysctl.d/99-disable_window_scaling.conf (see also sysctl):
This problem is caused by broken routers/firewalls, so let us change them. Some users have reported that the broken router was their very own DSL router.
More about it
This section is based on the LWN article TCP window scaling and broken routers and an archived Kernel Trap article: Window Scaling on the Internet.
There are also several relevant threads on the LKML.
Connected second PC unable to use bridged LAN
First PC have two LAN. Second PC have one LAN and connected to first PC. Lets go second PC to give all access to LAN after bridged interface:
This article or section needs expansion.
Источник