Tuesday, November 4, 2008

Restrict SSH access on linux

Have you ever thought to restrict login access to a linux server for security reasons?
One way is to delete any accounts who do not require. But for some reason we can not delete the accounts, because it needed for authentication such as POP3/IMAP.

Well, there's one more way to limit logins without the need to remove users from the system, namely restricting ssh access. How do we do?. We need to edit the OpenSSH configuration file.


[root@snowy ~]# vim /etc/ssh/sshd_config

to allow only user1 and user2, add the the directive 'AllowUser', example

AllowUsers user1 user2

or allow group1 and group2:

AllowGroups group1 group2


to block user user1 and user2, use 'DenyUsers'L

DenyUsers user1 user2

or deny group1 and group2

DenyGroups group1 group2

Save the file and restart the SSHD, assuming we use RHEL or Fedora:


[root@snowy ~]# service sshd restart

Stopping sshd: [ OK ]
Starting sshd: [ OK ]


Try login after that.

Monday, November 3, 2008

Argument list too long

Pernahkah mengalami hal seperti di bawah ini?:

[root@snowy clientmqueue]# rm -f *
-bash: /bin/rm: Argument list too long

Argument apa yg dimaksud?... oh ternyata perintah rm, mv ... dan lainnya (blum coba) punya batasan jumlah file yang bisa di handle. Perkiraan saya adalah 65535 (perlu dibuktikan).

Well, lupakan dulu itu, saya sedang diburu waktu karena file file ngga penting di /var/spool/clientmqueue ternyata menghabiskan space di /var dan bikin aplikasi laen tidak bisa nulis ke direktori itu misalkan syslog, php session etc.

Apa yang harus saya lakukan?. Insting saya mengatakan kita harus baca filenya satu persatu lalu menghapusnya. Ok let's do it (carefully!).

Ok kita coba testing dulu tanpa melakukan delete

cd /var/spool/clientmqueue/
ls -1|while read myfile; do echo $myfile; done

hasilnya:

[root@snowy clientmqueue]# ls -1|while read myfile; do echo $myfile; done
dfk21NE7J8006097
dfk22L2M7P012934
dfk23L27p3009736
dfk24L2KuP029846
dfk25L2Btp009903
dfk26L25hh025984
dfk27L27bF007017
dfk28L2633019792
^C

Sukses!!!.

ok kita tambahkan rm -f di perintah tadi:

[root@snowy clientmqueue]# ls -1|while read myfile;do echo $myfile;rm -f $myfile;done

Selesai!.