linux etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
linux etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster

Linux sunucuya en son giriş yapan kullanıcılar, last komutu ve lastlog kulanımı

Linux sunucularda yani Ubuntu, Centos, Debian, Redhat gibi tüm türev ve ana dağıtımlarda son giriş yapan kullanıcılar hakkında bilgi almak için aşağıdaki komutları kullanabilirsiniz.
Giriş yapan kullanıcıların bilgileri /var/log/wtmp dosyasında tutulur.
nano /var/log/wtmp

Bu dosyayı anlamlı görmek için stat, last, lastlog gibi komutları kullanabiliriz.

stat /var/log/wtmp

lastlog komutu; tüm kullanıcıların veya belirli bir kullanıcının en son girişini listeler.
lastlog

Detaylı kullanım için man komutu ile bilgi alınabilir.
man lastlog

lastlog -b 0 -t 30
Bugün harici son 30 gün giriş yapan kullanıcıların listesi.

last; komutu son giriş yapan kullanıcıların giriş yaptığı ip bilgilerini ve çıkış bilgilerini de gösterir.
last

last | head -10
head ile birlikte kullanıldığında istenilen kadarını göster diyebiliriz. Örnekte son 10 kayıt listenir.

last root | head -15
last ile kullanıcı adı yazıldığında sadece o kullanıya ait girişler listelenir. Örnekte root kullanıcısına ait son 15 giriş listelenir.

lastlog | more
more komutu tüm kayıtların belirli sayıda listelenip sizden gelecek olan boşluk ( space ) tuşu komutu ile sonraki sırayı gösterir.

last | more
last root | more

Kanak: https://makdos.blog/linux/372/linux-sunucuya-last-lastlog-giris-yapan-kullanicilar-detayli-bilgiler/

İzlenmesi gereken 12 kritik Linux log dosyası



What are Linux log files

Log files are a set of records that Linux maintains for the administrators to keep track of important events. They contain messages about the server, including the kernel, services and applications running on it. 
Linux provides a centralized repository of log files that can be located under the  /var/log directory.
The log files generated in a Linux environment can typically be classified into four different categories:
  • Application Logs
  • Event Logs
  • Service Logs
  • System Logs

Why monitor Linux log files

Log management is an integral part of any server administrator’s responsibility.
By monitoring Linux log files, you can gain detailed insight on server performance, security, error messages and underlying issues by. If you want to take a proactive vs. a reactive approach to server management, regular log file analysis is 100% required.
In short, log files allow you to anticipate upcoming issues before they actually occur. 

Which Linux log files to monitor

Monitoring and analyzing all of them can be a challenging task.
The sheer volume of logs can sometimes make it frustrating just to drill down and find the right file that contains the desired information.
To make it a little easier for you, we will introduce you to some of the most critical Linux log files that you must be monitoring.
Note: Please note that this is not an all-inclusive list - but just a subset of the important log files that matter the most. The more you can handle, the better it is for the health of your server. Listed below are the bare minimum that you must monitor without fail

/var/log/messages

What’s logged here?:

  • This log file contains generic system activity logs.
  • It is mainly used to store informational and non-critical system messages.
  • In Debian-based systems,  /var/log/syslog directory serves the same purpose.

How can I use these logs?:

  • Here you can track non-kernel boot errors, application-related service errors and the messages that are logged during system startup.
  • This is the first log file that the Linux administrators should check if something goes wrong.
  • For example, you are facing some issues with the sound card. To check if something went wrong during the system startup process, you can have a look at the messages stored in this log file. 

/var/log/auth.log

What’s logged here?

  • All authentication related events in Debian and Ubuntu server are logged here.
  • If you’re looking for anything involving the user authorization mechanism, you can find it in this log file.

How can I use these logs?:

Suspect that there might have been a security breach in your server? Notice a suspicious javascript file where it shouldn’t be? If so, then find this log file asap!
  • Investigate failed login attempts
  • Investigate brute-force attacks and other vulnerabilities related to user authorization mechanism.

/var/log/secure

What’s logged here?

RedHat and CentOS based systems use this log file instead of /var/log/auth.log. 
  • It is mainly used to track the usage of authorization systems.
  • It stores all security related messages including authentication failures.
  • It also tracks sudo logins, SSH logins and other errors logged by system security services daemon.

How can I use these logs?:

  • All user authentication events are logged here.
  • This log file can provide detailed insight about unauthorized or failed login attempts
  • Can be very useful to detect possible hacking attempts.
  • It also stores information about successful logins and tracks the activities of valid users.

/var/log/boot.log

What’s logged here?

  • The system initialization script, /etc/init.d/bootmisc.sh, sends all bootup messages to this log file
  • This is the repository of booting related information and messages logged during system startup process.

How can I use these logs?:

  • You should analyze this log file to investigate issues related to improper shutdown, unplanned reboots or booting failures.
  • Can also be useful to determine the duration of system downtime caused by an unexpected shutdown.

/var/log/dmesg

What’s logged here?

  • This log file contains Kernel ring buffer messages.
  • Information related to hardware devices and their drivers are logged here.
  • As the kernel detects physical hardware devices associated with the server during the booting process, it captures the device status, hardware errors and other generic messages.

How can I use these logs?:

  • This log file is useful for dedicated server customers mostly.
  • If a certain hardware is functioning improperly or not getting detected, then you can rely on this log file to troubleshoot the issue.
  • Or, you can purchase a managed server from us and we’ll monitor it for you.

/var/log/kern.log

What’s logged here?

This is a very important log file as it contains information logged by the kernel.

How can I use these logs?:

  • Perfect for troubleshooting kernel related errors and warnings.
  • Kernel logs can be helpful to troubleshoot a custom-built kernel.
  • Can also come handy in debugging hardware and connectivity issues.

/var/log/faillog

What’s logged here?

This file contains information on failed login attempts.

How can I use these logs?:

It can be a useful log file to find out any attempted security breaches involving username/password hacking and brute-force attacks.

/var/log/cron

What’s logged here?

This log file records information on cron jobs.

How can I use these logs

  • Whenever a cron job runs, this log file records all relevant information including successful execution and error messages in case of failures.
  • If you’re having problems with your scheduled cron, you need to check out this log file.

/var/log/yum.log

What’s logged here?

It contains the information that is logged when a new package is installed using the yum command.

How can I use these logs?:

  • Track the installation of system components and software packages.
  • Check the messages logged here to see whether a package was correctly installed or not.
  • Helps you troubleshoot issues related to software installations.
Suppose your server is behaving unusually and you suspect a recently installed software package to be the root cause for this issue. In such cases, you can check this log file to find out the packages that were installed recently and identify the malfunctioning program. 

/var/log/
maillog or /var/log/mail.log

What’s logged here?

All mail server related logs are stored here.

How can I use these logs?

  • Find information about postfix, smtpd, MailScanner, SpamAssassain or any other email related services running on the mail server.
  • Track all the emails that were sent or received during a particular period
  • Investigate failed mail delivery issues.
  • Get information about possible spamming attempts blocked by the mail server.
  • Trace the origin of an incoming email by scrutinizing this log file.

var/log/httpd/

What’s logged here?

  • This directory contains the logs recorded by the Apache server.
  • Apache server logging information are stored in two different log files – error_log and access_log.

How can I use these logs?:

  • The error_log contains messages related to httpd errors such as memory issues and other system related errors.
  • This is the place where Apache server writes events and error records encountered while processing httpd requests.
  • If something goes wrong with the Apache webserver, check this log for diagnostic information.
  • Besides the error-log file, Apache also maintains a separate list of access_log.
  • All access requests received over HTTP are stored in the access_log file.
  • Helps you keep track of every page served and every file loaded by Apache.
  • Logs the IP address and user ID of all clients that make connection requests to the server.
  • Stores information about the status of the access requests, – whether a response was sent successfully or the request resulted in a failure.

/var/log/mysqld.log or /var/log/mysql.log

What’s logged here?

  • As the name suggests, this is the MySQL log file.
  • All debug, failure and success messages related to the [mysqld] and [mysqld_safe] daemon are logged to this file.
  • RedHat, CentOS and Fedora stores MySQL logs under  /var/log/mysqld.log, while Debian and Ubuntu maintains the log in /var/log/mysql.log directory.

How can I use this log?

  • Use this log to identify problems while starting, running, or stopping mysqld.
  • Get information about client connections to the MySQL data directory
  • You can also setup ‘long_query_time’ parameter to log information about query locks and slow running queries.

Final Takeaway

While monitoring and analyzing all the log files generated by the system can be a difficult task, you can make use of a centralized log monitoring tool to simplify the process.
Some of our customers take advantage of using  Nagios Log Server to manage their server logs. There are many opensource options available if that’s out of the budget. Needless to say though, monitoring Linux logs manually is hard.
So if you want to take a truly proactive approach to server management, investing in a centralized log collection and analysis platform which allows you to view log data in real-time and set up alerts to notify you when potential threats arise.

Kaynak: https://www.eurovps.com/blog/important-linux-log-files-you-must-be-monitoring/

Linux Dosya Boyutu Öğrenme (du Komutu)







                                         

Linux Dosya Boyutu Öğrenme



du komutu(du command):

Linux ta dosya ya da dizinlerin boyutunu öğrenmek istediğimizde kullanacağımız komuttur.

Kullanımı oldukça basit :

du dosya_adi

eğer bir dizin hakkında bilgi almak istiyorsak

du dizin_adi 

ya da

du dizin_yolu (/home/ersin/Download) 


Ancak eğer dizin içerisinde bir çok dosya ve dizin varsa hepsini boyutlarıyla beraber listeleyecektir.

Bu durumda sadece ilgili dizinin boyutunu öğrenmek istiyorsak:

du -sh dizin_adi  

Eğer bir dizin içerisindeki sadece bir alt dizinlerinin boyutlarını öğrenmek isterseniz şu komutu

kullanmanız gerekecektir.


du -h --max-depth=1 /Klasör/yolu

--max-depth=2 olursa ağaç şeklinde düşünürsek iki alt dizine kadar inecektir.

-h  dosyanın daha okunaklı olması için kullanılır boyutu byte cinsinden değilde MB veya GB gösterir


Bir dizindeki tüm dosya ya da dizinlerin boyutunu öğrenmek istiyorsanız

du -sh * kumutunu kullanın

Bir dizindeki resimlerin ya da başka dosyaların boyutunu öğrenmek isterseniz

du -sh  *.txt          ya da         du -sh  *.jpg




du komutuyla beraber bir çok parametre kullanılabilmektedir. Onlardan bazıları ve kullanım amaçları

aşağıdaki gibidir.


-a    =  Sadece dizinler değil dosyalarında disk kullanımlarını gösterir.
-B   =  birim baytlık bloklar kullanır.
-b    =  Boyutlar bayt cinsinden gösterilir.
-c    =  Bir genel toplam gösterilir.
-D   =  dosya bir sembolik bağ dosyası ise hedefindeki disk kullanımı gösterilir.
-h   =  Boyutları, okunması kolay biçimde gösterir (1K 234M 2G gibi).
-m  =  Boyutları Megabyte olarak gösteril size=1M ile aynıdır.
-S   =  Alt dizinlerin boyutları hesaba katılmaz.
-s    =  Her argüman için sadece toplam gösterilir.
-x   =  Diğer dosya sistemleri üzerindeki dizinler hesaba katılmaz.
-X  =  dosya içindeki şablonlarla eşleşen dosyalar hesaba katılmaz.


Daha fazla bilgi için:

man du  komutunu kullanın.















Bash Kısayollar (Shortcuts – Hotkeys )



Ctrl + aİmleci satır başına götürür
Ctrl + eİmleci satır sonuna götürür
Ctrl + bİmleç bir karakter geri gider
Ctrl + fİmleç bir karakter ileri gider
Alt + bİmleç bir kelime geri gider
Alt + fİmleç bir kelime ileri gider
Ctrl+xxİmleç her defasında mevcut konumu ve satır başı arasında ileri/geri gider.
Ctrl + lEkranı temizler ve imleç en üst satıra konumlanır. clear komutuyla aynı işleve sahip.
Ctrl + uİmlec konumundan satır başına kadar siler. (imlecin solundaki her şeyi siler )
Ctrl + kİmlec konumundan satır sonuna kadar siler. ((imlecin sağındaki her şeyi siler )
Ctrl + wimleç konumundan bir önceki kelime başına kadar olan kısmı siler. Eğer imleç bir kelimenin ortasında ise o kelimenin imleçten önceki kısmını siler
Ctrl + timleçten önceki iki karakteri yer değiştir.
Esc + timleçten önceki iki kelimeyi yer değiştir.
Ctrl + cAktif çalışan prosese kill sinyali gönderir.
Ctrl + zAktif çalışan prosesi arkaplana (background) atar. Bu durumda Proses askıya alınmıştır. bg ile arkaplanda çalışması devam ettirilir. İstenirse proses tekrar fg komutu ile öne alınır
Ctrl + dAktif shell oturumuna exit komutu gönderir.
TabDosya, dizin, komut vb isimleri için otomatik tamamlama sağlar.
Ctrl + hBackspace tuşu gibi davranır.
Ctrl + rDaha önce kullanılmış komutlar arasında (History / Geçmiş) arama yapmanızı ve kullanmanızı sağlar
Alt + cKelimenin ilk harfini büyük yap
Alt + uİmlecin sağındaki kelimeyi büyük harf yap
Alt + lİmlecin sağındaki kelimeyi küçük harf yap

WINDOWS'u KALICI OLARAK LINUX'a BAĞLAMAK

      

 

  NTFS diski, Linux'a kalıcı olarak bağlamak



Bir çok kullanıcı Linux sistemin yanında ihtiyaç dolayısıyla Windows'u da kullanıyor. Bu yüzdendir 

ki Windows tarafında kullandığı dosyalara erişmek gerekebiliyor. Böyle bir durumda Linux'tan 

Windows'a  erişim yapabiliyor ancak başlangıçta windows disk bağlı olarak gelmiyor.


O halde ne yapmalı?

Windows'u , Linux'a kalıcı olarak bağlayalım.

Nasıl mı? 

Şöyle ki:


Terminal'i (Konsol ya da Uç birim ) açarak aşağıdaki konutu veriyoruz 

sudo fdsik -l 

sizden kullanıcı parolasını isteyecek  ve sınra aşağıdakine benzer bir çıktı verecek 




bunu yapmamızdaki amaç bağlamak istediğimiz disk bölümü  hangi bölümde.

Bu işlemi yaptıktan sonra yapmanız gerken şey bu disk bölümünü bağlamak için biz dizin(klasör) oluşturmak.

Eğer Home dizininde ki bir dizine bağlayacaksanız 

Terminalden mkdir dizin_adı (örnek mkdir win)  komutunu girin 


Eğer kök dizinine bağlayacaksanız mkdir dizin_adı demeniz yeterli olmayacak , bunun için  root 

yetkisi almanız gerekecek  sudo mkdir dizin_adı


Dizinimizide oluşturduğumuza göre artık bağlama işlemini gerçekleştirebiliriz.

Şimdi yapmamız gereken şey  fstab  dosyası içerisine değişiklik yapmak 


fstab (File System Table) nedir?

Linux disk yapılandırma bilgisini  fstab  isimli bir dosyada tutar. Bu dosya dağıtımlara göre

farklı isimlerde ve farklı yollarda olabilir.

Mint dağıtımındaki konumu olan  /etc/fstab yolundaki dosyayı  gedit metin editörüyle (yada bir başkası) açarak bağlama bilgilerini yazacağız. 
Şimdi aşağıdaki komutu veriyoruz.
  gedit  /etc/fstab 
Açılan metin editörü dosyasına aşağıdaki satırı kopyalaıyp yapıştırın.
/dev/sda4 /win ntfs defaults, umask=1000, gid=46 0 0
Siz bu bilgileri kendi disk ve oluşturduğunuz dizin adıyla değiştirip kaydedin.


*   /dev/sda4 benim bağlamak istediğim disk bölümü( Windows sistemde D dizinim)

* /win benim diski bağlamak için yukarıda oluşturduğum dizin_adi (Bu arada ben kök dizine bağladım)


Hepsi bu kadar :)