Showing posts with label SSH. Show all posts
Showing posts with label SSH. Show all posts

Monday, 1 April 2013

How to set an idle timeout interval for SSH users

User can login to server via ssh and you can set an idel timeout interval to avoid unattended ssh session.
We need to edit ssh configuration file "/etc/ssh/sshd_config"


[root@mani-sys ~]# vim /etc/ssh/sshd_config 

ClientAliveInterval 300                             ### line 120
ClientAliveCountMax 0

Save and exit the file.

You are setting an idle timeout interval in seconds (300 secs = 5 minutes).After this interval has passed, the idle user will be automatically logged out.


Now restart the ssh service

[root@mani-sys ~]# /etc/init.d/sshd restart
Stopping sshd:                                             [  OK  ]
Starting sshd:                                             [  OK  ]
[root@mani-sys ~]# 

I hope this helps....

Friday, 6 April 2012

Kill idle SSH sessions on linux


First check how many user current logged in server using "w" command




View all SSH sessions processes id using "pstree  -p" command





kill idle ssh session using "kill  PID" command



I hope, this would resolve your issue.

Friday, 23 March 2012

SSH login without password in linux

You can login to a remote Linux server without entering password using ssh-keygen.

Create public and private keys using "ssh-keygen" on local-host. ssh-keygen have two algorithm  tsa and rsa.


 root@manivel-admin:~#   ssh-keygen   -t  rsa

Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): -->Press Enter
Enter passphrase (empty for no passphrase):  --------->    Press Enter
Enter same passphrase again:                     ------------->   Press Enter
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
94:94:60:5a:5f:e8:ef:7f:6d:02:3b:f9:88:39:d2:6f root@manivel-admin
The key's randomart image is:
+--[ RSA 2048]----+
|      +..o.      |
|     + ooo       |
|    .  .+        |
|       ..        |
|        S.       |
|          . .    |
|         o   + . |
|        . +oE.o o|
|         .o=++.o |
+-----------------+
root@manivel-admin:~# 

Copy the public key localhost to remote-host using "scp" command.

  root@manivel-admin:~# scp  -r  .ssh/id_rsa.pub  test@10.2.12.1:/home/test/.ssh/authorized_keys

Notes: If  .ssh directory is not there in /home/test/ .You will create .ssh


We need to set permission for .ssh directory and authorized_keys file in "Remote host".

  test@manivel:~$  chmod  755  .ssh/

  test@manivel:~$  chmod  644  .ssh/authorized_keys

Login to remote-host without entering the password

  root@manivel-admin:~#   ssh   test@10.2.12.1
                    [Note: SSH did not ask for password.]

  test@manivel:~$  [Note: You are on remote-host here]

Sunday, 15 January 2012

SSH installation on Centos

We need to install two package
                 1. Openssh-server
                 2. Openssh-clients

First check Openssh-server and Openssh-clients packages installed or not

  [root@sysadmin sysadmin]#  rpm  -qa   openssh*
output would like this

openssh-clients-5.3p1-70.el6_2.2.x86_64
openssh-askpass-5.3p1-70.el6_2.2.x86_64
openssh-server-5.3p1-70.el6_2.2.x86_64
openssh-5.3p1-70.el6_2.2.x86_64

You did not get above output .You need to install the Openssh packages ( which are installed by default untill and unless you removed it or skipped it while installing Centos)


           [root@sysadmin sysadmin]#  yum   install  openssh-server   openssh-clients

Then start the SSH service

          [root@sysadmin sysadmin]#   /etc/init.d/sshd   start

After that check SSH service running or not

          [root@sysadmin sysadmin]#   /etc/init.d/sshd   status

If you want to restart the service , using restart command

          [root@sysadmin sysadmin]#   /etc/init.d/sshd   restart

SSH starts automatically whenever the system boot so we will run this command

           [root@sysadmin sysadmin]#   chkconfig   sshd   on