{"id":4025,"date":"2021-02-03T23:16:25","date_gmt":"2021-02-03T23:16:25","guid":{"rendered":"https:\/\/linuxways.net\/?p=4025"},"modified":"2021-02-03T23:16:28","modified_gmt":"2021-02-03T23:16:28","slug":"how-to-view-standard-log-files-on-ubuntu-linux-servers","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/ubuntu\/how-to-view-standard-log-files-on-ubuntu-linux-servers\/","title":{"rendered":"How to View Standard Log Files on Ubuntu Linux Servers"},"content":{"rendered":"<p>Logs are extremely useful when troubleshooting system, application or network problems. Information captured in log files may also be analyzed to uncover patterns that can help you make informed decisions as a system admin.<\/p>\n<p>This guide briefly explains how you can view standard log files on Ubuntu Linux servers.<\/p>\n<h2>Important commands for working with log files<\/h2>\n<p>On Ubuntu Linux servers, logs are normally stored in plain text format. Hence, it is important that you know the following basic Linux commands for moving around the filesystem and working with text files via the Ubuntu terminal.<\/p>\n<p><strong>cd<\/strong> &#8211; change directory<\/p>\n<p><strong>ls<\/strong> &#8211; display the contents of a directory<\/p>\n<p><strong>cp<\/strong> &#8211; copy files or folders<\/p>\n<p><strong>mv<\/strong> &#8211; rename\/move files or folders<\/p>\n<p><strong>nano<\/strong> &#8211; console-based text editor<\/p>\n<p><strong>less<\/strong> &#8211; view the content of a text file one page at a time<\/p>\n<p><strong>head<\/strong> &#8211; display the first 10 lines of a text file<\/p>\n<p><strong>tail<\/strong> &#8211; view the last 10 lines of a text file<\/p>\n<p><strong>grep<\/strong> &#8211; search for specific keywords in a text file or output data<\/p>\n<h2>Location of log files on Ubuntu servers<\/h2>\n<p>Basically, log files are stored under the<strong> \/var\/log<\/strong> directory on Ubuntu servers. Run the command below to change the directory to \/var\/log.<\/p>\n<pre>$ <strong>cd \/var\/log<\/strong><\/pre>\n<p>Now, you may list the content of \/var\/log as follows.<\/p>\n<pre><strong>$ ls<\/strong><\/pre>\n<p>As seen in figure 1 below, the \/var\/log directory contains several log files that can be broadly categorized into system logs and application logs.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"713\" height=\"229\" class=\"wp-image-4026\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-21.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-21.png 713w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-21-300x96.png 300w\" sizes=\"auto, (max-width: 713px) 100vw, 713px\" \/><\/p>\n<p><strong>Figure 1: List log files on Ubuntu server<\/strong><\/p>\n<h2>System logs<\/h2>\n<p>System logs contain information about the operation of the Ubuntu system; including authorization logs, kernel logs, kernel ring buffer, and general system events.<\/p>\n<h3>Authorization logs<\/h3>\n<p>Authorization logs are stored in <strong>\/var\/log\/auth.log<\/strong>. This is where you will find information about user authorization attempts; including the use of the sudo command.<\/p>\n<p>You may run the command below to inspect the content of the auth.log file.<\/p>\n<pre>$ <strong>sudo less \/var\/log\/auth.log<\/strong><\/pre>\n<p><strong>Note: <\/strong>Hit the spacebar on your keyboard to scroll from page to page. Press <strong>q <\/strong>to exit.<\/p>\n<p>You could also use the grep command to filter the information in the logs. Here is an example.<\/p>\n<pre>$ <strong>sudo less \/var\/log\/auth.log | grep olu<\/strong><\/pre>\n<p>The information in the <strong>sample output<\/strong> below indicates that there was a successful remote login to my Ubuntu server via ssh by user olu.<\/p>\n<table>\n<tbody>\n<tr>\n<td>Feb 1 15:44:24 Ubuntu sshd[1594]: Accepted publickey for olu from 105.0.0.100 port 35233 ssh2: RSA SHA256:B3zi4x3gdF89wm0GZw+fsAkhckLEsx8fJ0GJiU80CXH<\/p>\n<p>Feb 1 15:44:24 Ubuntu sshd[1594]: pam_unix(sshd:session): session opened for user olu by (uid=0)<\/p>\n<p>Feb 1 15:44:24 Ubuntu systemd-logind[747]: New session 2 of user olu.<\/p>\n<p>Feb 1 15:44:24 Ubuntu systemd: pam_unix(systemd-user:session): session opened for user olu by (uid=0)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Kernel logs<\/h3>\n<p>Kernel logs are held in <strong>\/var\/log\/kern.log<\/strong>. This information is useful for troubleshooting kernel errors. The kernel controls everything in the operating system; including process management, memory management and device management.<\/p>\n<p>Use the following command to display the content of the kern.log file one page at a time.<\/p>\n<pre>$ <strong>sudo less \/var\/log\/kern.log<\/strong><\/pre>\n<p>Or try this to display the first 10 lines of the kern.log file.<\/p>\n<pre>$ <strong>sudo head \/var\/log\/kern.log<\/strong><\/pre>\n<p>Find specific information in kern.log.<\/p>\n<pre>$ <strong>grep memory \/var\/log\/kern.log<\/strong><\/pre>\n<h3>Kernel ring buffer<\/h3>\n<p>The kernel ring buffer holds kernel hardware information. The information is logged in <strong>\/var\/log\/dmesg<\/strong> and can be displayed by using the <strong>dmesg<\/strong> command. This information includes all detected devices at system boot time.<\/p>\n<p>You can use this to troubleshoot issues with server hardware components. Run the command below to view the entire content of the kernel ring buffer.<\/p>\n<pre><strong>$ dmesg<\/strong><\/pre>\n<p>Try the next command to display the last 10 lines of the kernel ring buffer.<\/p>\n<pre>$ <strong>dmesg | tail<\/strong><\/pre>\n<p>Or filter for specific keywords using grep.<\/p>\n<pre><strong>$ dmesg | grep cpu<\/strong><\/pre>\n<h3>General system logs<\/h3>\n<p>Here, we are going to talk about <strong>syslog<\/strong> and <strong>journalctl<\/strong><\/p>\n<h4>Syslog<\/h4>\n<p>Syslog is a logging mechanism that stores general system events in <strong>\/var\/log\/syslog<\/strong>. The information stored here may include events that you may not find in other log files.<\/p>\n<p>Run the command below to display the content of the syslog file page by page.<\/p>\n<pre>$ <strong>sudo less \/var\/log\/syslog<\/strong><\/pre>\n<p>You could also search for specific keywords using the <strong>grep<\/strong> command as follows.<\/p>\n<pre>$ <strong>sudo grep failed \/var\/log\/syslog<\/strong><\/pre>\n<h4>Journalctl<\/h4>\n<p>The journalctl command simplifies the process of examining server logs. Rather than look through individual log files, you could use journalctl to quickly find and filter the information that you need.<\/p>\n<p>The command below displays all log entries from oldest to newest.<\/p>\n<pre><strong>$ journalctl<\/strong><\/pre>\n<p>The next command shows warning messages.<\/p>\n<pre><strong>$ journalctl -p warning<\/strong><\/pre>\n<p>You can display only kernel messages as follows.<\/p>\n<pre><strong>$ journalctl --dmesg<\/strong><\/pre>\n<p>You can search for specific keywords by combining the <strong>grep<\/strong> command and view results page by page using <strong>less<\/strong>.<\/p>\n<pre><strong>$ journalctl | grep ssh | less<\/strong><\/pre>\n<p>View log information since a specific date.<\/p>\n<pre><strong>$ journalctl --since=2021-02-01<\/strong><\/pre>\n<p>Or view log information since a specific time.<\/p>\n<pre><strong>$ journalctl --since=12:00<\/strong><\/pre>\n<p>You could also type <strong>journalctl<\/strong> and then press the tab key on your keyboard to see available options.<\/p>\n<h2>Application Logs<\/h2>\n<p>Several applications store log information under <strong>\/var\/log<\/strong>. For example, in figure 1 above, the <strong>clamav<\/strong> directory contains log files pertaining to the ClamAV anti-malware application.<\/p>\n<p>Here are some examples of popular applications or services and where their log information is stored.<\/p>\n<pre>Apache web server logs - <strong>\/var\/log\/apache2<\/strong><\/pre>\n<pre>NGINX web server logs - <strong>\/var\/log\/nginx<\/strong><\/pre>\n<pre>Printing system (CUPS) logs - <strong>\/var\/log\/cups<\/strong><\/pre>\n<h2>Other Useful Logs<\/h2>\n<p>Some log files such as <strong>lastlog<\/strong>, <strong>wtmp<\/strong> may not be directly read by humans. The following is a brief explanation of what type of information these files contain and how you can view it.<\/p>\n<h3>lastlog<\/h3>\n<p>The information held in <strong>\/var\/log\/lastlog <\/strong>pertains to users and their most recent login to the Ubuntu server. You would need to use the <strong>lastlog<\/strong> command to access it as follows.<\/p>\n<pre>$ <strong>lastlog<\/strong><\/pre>\n<h3>wtmp<\/h3>\n<p>The <strong>var\/log\/wtmp<\/strong> file holds comprehensive login records.<\/p>\n<p>Run the <strong>last<\/strong> command to display a list of last logged in users. You may also see information about system boot\/reboot.<\/p>\n<pre>$ <strong>last<\/strong><\/pre>\n<p>Run the <strong>who <\/strong>command to see who is currently logged in.<\/p>\n<pre>$ <strong>who<\/strong><\/pre>\n<p>The <strong>w<\/strong> command shows you who is currently logged in and what they are doing on the Ubuntu server.<\/p>\n<pre>$ <strong>w<\/strong><\/pre>\n<h2>Conclusion<\/h2>\n<p>In this guide, we have briefly covered how to view standard log files on Ubuntu servers. This is not an exhaustive list but we hope that it gives you an idea of where to look.<\/p>","protected":false},"excerpt":{"rendered":"<p>Logs are extremely useful when troubleshooting system, application or network problems. Information captured in log files may also be analyzed to uncover patterns that can help you make&hellip;<\/p>","protected":false},"author":28,"featured_media":4028,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[35,174,100],"class_list":["post-4025","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ubuntu","tag-linux","tag-log-files","tag-ubuntu-20-04"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/4025","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/28"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=4025"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/4025\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/4028"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=4025"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=4025"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=4025"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}