Archive for the ‘FreeBSD Commands’ Category

Create and work with compressed files

Sunday, September 19th, 2010

Creating and working with compressed files in FreeBSD server is an easy task.

to compress a file you can use

#gzip filename

to compress each file in a directory,each file will be compressed in one file.

#gzip -r directory-name

to compress all files in a single archive:

#tar -zcvf  archive-name.gz directory-name.

to uncompress an archive:

#tar -zxvf archive-name.gz -C /directory-name

also to uncompress an archive:

#gzip -d archive.gz

to uncompress each file in a directory use

#gzip -d folder-name

Change Default SSH Port to Protect FreeBSD server from daily spam attack

Saturday, September 18th, 2010

Change Default SSH Port to Protect your FreeBSD server from daily spam attack.

# ee /etc/ssh/sshd_config

look for line #port 22 and change it to port 1234 then press Esc, save and exit.

reboot the server

#shutdown -r now

or type this command to reload SSH

# /etc/rc.d/sshd reload

Create a new user and Change User Password

Saturday, September 18th, 2010

To Add a new user you can use adduser command, and it ask you for user information step by step.

To Change user password use passwd command

Example

#passwd Joo –> will let you change the password for user Joo.

#passwd  –> will let you change the password for current user.

FreeBSD server status

Wednesday, June 9th, 2010

There is many tools and commands you can use to monitor the status of FreeBSD server like :

  • #top   , it will display the top processes on the system and  continue updates this  information, to exist press Ctrl+C
  • #last , it will list the sessions in reverse time order.
  • # cat /var/log/auth.log , it will disply auto.log info.
  • #cat /var/log/messages , it will disply messages info.
  • #netstat -r , it display a list of network status.
  • #freecolor , it display used/free Physical , and Swap memory.
  • #ps , to display process status.

FreeBSD view system log

Tuesday, March 9th, 2010

One of the daily operations as FreeBSD administrator is to check system log and system resources usage, also system logs are my favorite friend to debug and solve system problems.

Here  a summary list for commands used to check system log.

  1. cat /var/log/messages will display all the system log
  2. tail -f /var/log/messages will display the tail of system log, use Ctrl+C to exit.
  3. less /var/log/messages will display system log page by page, press Q to exit.
  4. cat /var/log/messages | grep error will display only the lines contain the keyword error.
  5. vi /var/log/messages use :q to exit vi viewer (vi is the default editor that comes with the UNIX operating)

Other important logs you should check:

  1. cat /var/log/auth.log | grep error
  2. cat /var/log/maillog | grep error

FreeBSD Commands

Sunday, March 7th, 2010

Here is summary list for FreeBSD commands usually need and use:

  1. #pwd : get the current directory.
  2. #whoami get current user.
  3. #ls : list the files, only file names will be listed , its like dir command in the DOS.
  4. #ls -l : list the files, with detail information about files like file permission, owner, group, date, and size  , its like dir command in the DOS.
  5. #cd : to change directory.
  6. #man command: get the manual syntax and usage for the given command.
  7. #man -k keyword: search the manual for the given keyword.
  8. #cat filename: view the contents of the given file.
  9. #locate filename: serach for the location of the given file, its very fast.
  10. #/usr/libexec/locate.updatedb: to update locate database lookup file.
  11. #ee filename: edit the given file.
  12. #shutdown -r now: reboot the server immediately.
  13. #su: switch the current user to the root user.
  14. #fetch url: to download a url using http of ftp.
  15. #cp oldfilename newfilename: copy a file or directory to a new one.
  16. #cp -R oldfilename newfilename: copy a file or directory to a new one and all sub directories.
  17. #rm filename : delete and remove a file or directory.
  18. #rm -R filename : delete and remove a file or directory and all sub directories.
  19. #mv oldfilename newfilename: move  file to a new location.
  20. #mv -R oldfilename newfilename: move  file to a new location and all sub directories.
  21. #find /size + 100000k search for files that is larger than 100000k.