Very essential Debian commands
Posted by Md. Mahidul Hasan on 3:20 PM with No comments
Very essential Debian commands
Update the debian package list:
root@mahidul:~root@mahidul:~# apt-get update
Upgrade your debian packages:
root@mahidul:~# apt-get upgrade
Upgrade debian to newer version,
root@mahidul:~# apt-get dist-upgrade
caution: this may also corrupt your system if you don't have a deeper understanding in Linux don't use it.
Setting the date and time:
root@mahidul:~# date ### check the date
root@mahidul:~# date --set 12:33:00 ### setting time
root@mahidul:~# date --set 05-05-2011 ### setting date
root@mahidul:~# hwclock --systohc ### sysncronizing
Or
root@mahidul:~# date
root@mahidul:~# date 041516022011
root@mahidul:~# hwclock --systohc
For Selecting time zone
root@mahidul:~# dpkg-reconfigure tzdata
For showing Debian version:
root@mahidul:~# more /etc/issue
DNS show up:
root@mahidul:~# vim /etc/resolv.conf
Change the host and domain name:
root@mahidul:~# vim /etc/hosts
root@mahidul:~# vim /etc/hostname
root@mahidul:~# cp /etc/hosts /var/spool/postfix/etc/
root@mahidul:~# vim /etc/postfix/transport
root@mahidul:~# vim /etc/postfix/main.cf
Creating a user account:
root@mahidul:~# adduser username
root@mahidul:~# passwd yourpassword
If you want to give a dot (.) like user.name then,
root@mahidul:~# adduser --force-badname user.name (For forcefully write)
Or, you can first add a user then add dot (.) the below files.
root@mahidul:~# vim /etc/passwd
user.name (add a dot(.) between bolcorpbd)
root@mahidul:~# vim /etc/shadow
user.name (add a dot(.) between bolcorpbd)
root@mahidul:~# vim /etc/groups
user.name (add a dot(.) between bolcorpbd)
Changing password:
root@mahidul:~# passwd username
root@mahidul:~# new password: (your new password)
root@mahidul:~# re-type password: (your new password)
Delete user with directory:
root@mahidul:~# userdel bolcorp
root@mahidul:~# rm -rf bolcorp
Delete only user:
root@mahidul:~# deluser bolcorp Or userdel bolcorp Or rm-rf bolcorp.bd
For creating IP forwarding:
root@mahidul:~# Vim /etc/sysctl.conf
Net.ipv4.ip_forward = 1 (UNCOMMENT THE FOLLOWING LINE)
For IP forwarding checking:
root@mahidul:~# Sysctl -p
Cache delete from squid:
root@mahidul:~# cd /var/spool/squid
root@mahidul:~# ls
root@mahidul:~# rm –rf*
If configuration is ok but still can not browse then
root@mahidul:~# cd /var/spool/squid/
root@mahidul:~# rm -rf swap.state
root@mahidul:~# rm -rf swap.state.last-clean
root@mahidul:~# /etc/init.d/squid restart
Checking squid status:
root@mahidul:~# pgrep squid
2271 }
2274 } than squid process is ok
then check cache.log for checking errors,
root@mahidul:~# tail -f /var/log/squid/cache.log
This is how you will get the log report with date/time format.
root@mahidul:~# tail -f /var/log/squid/access.log | perl -pe 's/[\d\.]+/localtime($&)/e'
root@mahidul:~# grep 192.168.0.14 /var/log/squid/access.log | perl -pe 's/[\d\.]+/localtime($&)/e'
To close a running process: (List the details of a single process)
root@mahidul:~# ps aux | grep dansguardian
root@mahidul:~# pkill-9 dansguardian
For showing mail send /Receive:
root@mahidul:~# tail –f/var/log/mail.log
root@mahidul:~# Mlog
To Show client bandwidth for particular user PC:
root@mahidul:~# ifconfig (to see what type LAN are using such as wth0,eth1)
root@mahidul:~# if top –I eth1
Mail Sending via telnet:
root@mahidul:~# telnet localhot 25
Telnetlocalhost trying 127.0.0.1…
Connected to localhost.localdomain(127.0.0.1)
Escape character is`^`]:
220 mail.ocl-bd.com ESMTP Postfix(2.2.2)
Helo sam
250 mail.ocl-bd.com
Mail from:sam@ocl-bd.com
250 OK
Rcpt to:anamul@bol-online.com
250 Ok
Data
354 End data with <CR><LF><CR><LF>
Test mail
.
250 Ok: queued as 57DFF2884C9
Quit
Mail Box size check:
root@mahidul:~# cd /var/spool/mail
root@mahidul:~# ls –alh
root@mahidul:~# cd /var/mail
Mail box details:
root@mahidul:~# alpine –f /var/spool/mail/username
root@mahidul:~# pine –f /var/spool/mail/username
root@mahidul:~# GetMail username
For showing Particular mail account:
root@mahidul:~# grep corp@vashi.com /var/log/mail.log
For check previous mail:
root@mahidul:~# ped
root@mahidul:~# ls
root@mahidul:~# grep “from <”masud@online.com”>” mail.log
Aliasing in Group:
root@mahidul:~# vim /etc/postfix/aliases
#See man 5 aliases for format
postmaster: root
#groupname: username1,username2
toall: mahidul,test,info
root@mahidul:~# postalias aliases
root@mahidul:~# /etc/init.d/postfix restart
Auto Replay (vacation mail) of the account:
root@mahidul:~# cd /home
root@mahidul:~# ls
root@mahidul:~# cd username
root@mahidul:~# vim message
root@mahidul:~# message paste (place user massage and save the file using ESC+SHIFT+:)
root@mahidul:~# ls -alh
root@mahidul:~# mv forward .forward
root@mahidul:~# mv procmailrc .procmailrc
If Auto Replay is not configured :
root@mahidul:~# apt-get install procmail (press enter)
root@mahidul:~# cd /home/(username) press enter
root@mahidul:~# ls -al press enter
root@mahidul:~# vim .procmailrc
###Now write these script,
#SHELL=/bin/sh
#MAILDIR=$HOME/Mail
#DEFAULT=/var/spool/mail/rafii.zaman
#LOGFILE=$MAILDIR/from
#LOGFILE=/var/log/procmail.log
#LOCKFILE=$HOME/.lockmail
# Anything that has not been delivered by now will go to $DEFAULT
# using LOCKFILE=$DEFAULT$LOCKEXT
#:0 h c
# * !^FROM_DAEMON
# * !^X-Loop: rafii.zaman@dzvilo.com
# | (formail -r -I"Precedence: auto-reply"
# -A"X-Loop: rafii.zaman@dzvilo.com" ;
# cat $HOME/message; \
# ) | $SENDMAIL -oi .t
SHELL=/bin/sh
:0 h c
* !^FROM_DAEMON
* !^X-Loop: rafii.zaman@dzvilo.com
| (formail -r -I"Precedence:junk" \
-A"X-Loop: rafii.zaman@dzvilo.com" ; \
cat $HOME/message; \
) | $SENDMAIL -oi -t
:0
###Then save the file.
root@mahidul:~# vim .forward (press enter)
|/usr/bin/procmail (write the following path)
root@mahidul:~# vim message (press enter)
write down the message which will be Auto replied then save the file.
Removing Auto Replay to an email account:
root@mahidul:~# cd /home/
root@mahidul:~# ls -alh
root@mahidul:~# cd username
root@mahidul:~# mv .forward forward
root@mahidul:~# mv .procmailrc procmailrc
Spam Whitelist user ID: (To show free spam mail)
root@mahidul:~# vim /etc/MailScanner/rules/spam.whitelist.rules
root@mahidul:~# /etc/init.d/openprotect restart
Spam whitelist:
root@mahidul:~# vim /opt/MailScanner-4.82.6-1/etc/rules/spam.whitelist.rules
Spam Site list:
root@mahidul:~# vim /opt/MailScanner/etc/spam.lists.conf
###Add you spam white list here.
# This is where you can build a Spam WhiteList
# Addresses matching in here, with the value
# "yes" will never be marked as spam.
#From: 152.78. yes
#From: 130.246. yes
FromOrTo: yahoo.cn yes
FromOrTo: hpchuazhong.com yes
FromOrTo: sgdgroup.com yes
FromOrTo: tientuan.com.vn yes
FromOrTo: buznan@ifotam.com.pl Yes
FromOrTo: default no
If SMTP not working / Mail not sending:
root@mahidul:~# Ps –ef | grep dovecot (To show dovecot running / not)
root@mahidul:~# /etc/init.d/dovecot stop
root@mahidul:~# /etc/init.d/dovecot start
root@mahidul:~# telnet clint IP 25 (first check client side)
Check local connection ok?
root@mahidul:~# mii-tool
root@mahidul:~# arp –n
root@mahidul:~# tail –f /var/log/squid/access.log
Uninstall a package:
root@mahidul:~# apt-get --purge remove packagename
Client side :
root@mahidul:~# telnet clientip 25
Show Mail queue:
root@mahidul:~# mailq
Mail queue flash :
root@mahidul:~# postfix flash
or
root@mahidul:~# postfix -f
you will list all of the mails which are queued or simply timed out for some reason. If you want to remove a mail from the "mailq" type:
root@mahidul:~# postsuper -d mailID
To remove all mail from the queue:
root@mahidul:~# postsuper -d ALL
Sometime mailscaner holds the mail in que but could not flush then you have to reque the mails like this way:
root@mahidul:~# postsuper -r ALL
To remove all mails in the deferred queue:
root@mahidul:~# postsuper -d ALL deferred
Copy from another server:
root@mahidul:~# scp MailScanner-install-4.82.6-1.tar.gz 202.161.190.238:/home/mahfuj/
Copy Files from one server(A) to other(B) (While logged into A):
root@mahidul:~# scp –p 78 FILENAME USERNAME@ADDRESS_OF_REMOTE_SERVER:FILENAME
For example:
root@mahidul:~# scp /home/jlwallen/sample.pdf jlwallen@192.168.1.2:/home/jlwallen/sample.pdf
Copy Directory: from A to B(While logged into A):
root@mahidul:~# scp –r –p78 /home/jlwallen/TEMP jlwallen@192.168.1.2:/home/jlwallen/TEMP
Show all processes:
root@mahidul:~# ps aux //similar to ps ux but it would show the process of every user as well as the system.
which will print out something like:
113 2596 0.0 0.5 17852 11460 ? Ss 06:49 0:00 /usr/sbin/dansguardian
Now we can see the PID of Dansguardian is 2596. We can kill this with the kill 2956 command.
Web browsing package:
root@mahidul:~# apt-get install lynx
root@mahidul:~# lynx www.yahoo.com // use lynx command to browse
Find out a installed package:
root@mahidul:~# whereis filename
root@mahidul:~# find filename
root@mahidul:~# finger filename
Show folder Size:
root@mahidul:~# du -h
Show pertition Details:
root@mahidul:~# df -h
Format command in linux:
root@mahidul:~# sudo mkfs -t ext3 /dev/hda1
Search a file:
root@mahidul:~# find /-name testfile
Find a new connected device:
root@mahidul:~# fdisk -l
Categories: Very essential Debian commands
0 comments:
Post a Comment