Mateen Ahmed

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Monday, 10 December 2012

Configuring ssh Server

Posted on 00:53 by Unknown
                                                     SSH SERVER CONFIGURATIONS
ssh command is a client remote login program to connect remote system and for executing commands on remote system. This program provides secure encrypted communication over an insecure network. By default you can use ssh to login remote system using any user with a valid password.
If your DNS server is configured you can use host name to login, else if not, you need to use ip address of the remote system to login.

Get pid of sshd demon

pgrep command can be used to check the pid of sshd demon
pgrep sshd

Configuring /etc/ssh/sshd_config

Location: /etc/ssh/sshd_config                          Permission: 0600 (rw-------)                          Ownership: root : root

Version

ssh Server by default run as Version 2, but can also run as Version 1 but not recommended.  The Version can be changed by changing the parameter of Protocol in /etc/ssh/sshd_conf from Protocol 2 to Protocol 1.

Changing default port on which sshd demon listens

The port on which sshd demon listen can be changed by editing the value of variable Port to the required port number in /etc/ssh/sshd_config file, say:
Port 123
Before choosing the port you can check if the port you chose is not being used of any other service as:
netstat -an | grep <portnumber to search>
After you have made changes to sshd_config file, you need to restart the sshd demon as service sshd restart. Now to connect to this machine remotely, you need to connect as:
ssh -p 123 192.168.1.25

If you also want to specify the user, you can specify as:
ssh -p 123 sunil@192.168.1.25

Configuring ssh to Listen on specific ip address(s)

By default sshd demon will listen on all the IPs of all the network card. The default entry for this is in /etc/ssh/sshd_conf as:
#ListenAddress 0.0.0.0
#ListenAddress ::
You can note that these entries are # marked meaning there by that they are commented, but are written only to show that what the default value is for ListenAddress.
You can configure your sshd demon to listen on specific IP address, by changing the value of ListenAddress as
ListenAddress 192.168.1.26
If you what your sshd demon to listen on more than one IP address, you need to make ListenAddress <ip-address> for each ip address, one per line as
ListenAddress 192.168.1.26
ListenAddress 192.168.1.24

Configure ssh to Listen on specific port of specific ip address(s)

You can also configure your sshd demon to communication on specific port for a specific ip address. This can be done by changing the value of ListenAddress in /etc/ssh/sshd_config as:
ListenAddress 192.168.1.26:123
ListenAddress 192.168.1.24:456

So, now sshd demon will listen on port 123 for ip address 192.168.1.26, and will listen on port 456 for ip 192.168.1.24.

Displaying Banner when ssh Session starts after successful login

In some jurisdictions, sending a warning message before authentication may be relevant for getting legal protection.  The contents of the specified file are sent to the remote user before authentication is allowed.  This option is only available for protocol version 2.  By default, no banner is displayed.

Edit /etc/ssh/sshd_config file, look for Banner and Edit the the path of Banner. Create a file named /etc/ssh/hackers.banner and the relevant contents you want to display on successfull login and restart sshd demon as
Banner /etc/ssh/hackers.banner
service sshd restart

Permitting ssh to specific user

To permit specific users(s), this keyword can be followed by a list of user name patterns, separated by spaces.  If specified, login is allowed only for user names that match one of the patterns.  ‘*’ and ‘?’ can be used as wildcards in the patterns.  Only user names are valid; a numerical user ID is not recognized.  By default, login is allowed for all users.  If the pattern takes the form USER@HOST then USER and HOST are separately checked, restricting logins to particular users from particular hosts. More than one user can be specified by separating them with white space.

Example 1:

Add the following on ssh server (192.168.1.250) in /etc/ssh/sshd_config file and restart sshd daemon:
AllowUsers s*a

This will allow all the users having username starting with "s" and ending with "a". No other user is allowed to ssh  to 192.168.1.250.

Example 2:

Add the following on ssh server (192.168.1.250) in /etc/ssh/sshd_config file and restart sshd daemon:
AllowUsers s?????

This will allow all the users having username starting with "s" followed by any but exactly 5 character. No other user is allowed to ssh  to 192.168.1.250.

Example 3:

Add the following on ssh server (192.168.1.250) in /etc/ssh/sshd_config file and restart sshd daemon:
AllowUsers shreya@192.168.1.249
AllowUsers visesh@192.168.1.2

Now, user shreya can ssh only from 192.168.1.249 and user visesh is allowed to ssh only from 192.168.1.2. No other user is allowed to ssh to 192.168.1.250.

Permitting ssh to specific group

This keyword can be followed by a list of group name patterns, separated by spaces.  If specified, login is allowed only for users whose primary group or supplementary group list matches one of the patterns.  ‘*’ and ‘?’ can be used as wildcards in the patterns.  Only group names are valid; a numerical group ID is not recognized.  By default, login is allowed for all groups. More than one group can be specified by separating them with white space.

Example 1:

Add the following on ssh server (192.168.1.250) in /etc/ssh/sshd_config file and restart sshd daemon:
AllowGroups ad*

This will allow all the users whose primary group or supplementary group named begining with "ad". No other user is allowed to ssh  to 192.168.1.250.

Example 2:

Add the following on ssh server (192.168.1.250) in /etc/ssh/sshd_config file and restart sshd daemon:
AllowGroups dba?????

This will allow all the users whose primary group or supplementary group named begining with dba followed by any but exactly 5 character. No other user is allowed to ssh  to 192.168.1.250.

ssh to specific remote user

If you want to ssh to specific user, you can do that as:
ssh sunil@192.168.1.25

where sunil is the user on 192.168.1.25 to who you want to ssh.

Executing command remotely using ssh

You can execute almost any command on remote system as:
ssh 192.168.1.24 "df -h"

sending message using ssh

You can use ssh command to send message to other using on specific console as
ssh 172.24.0.15 ‘echo “hello users” > /dev/pts/0’
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Posted in | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • Linux Kernel /etc/sysctl.conf
    /etc/sysctl.conf can be a powerful way of changing kernel settings at run-time. If you have sysctl.conf support compiled into your kernel, y...
  • Domain name formulation
    The right-most label conveys the top-level domain; for example, the domain name  www.example.com  belongs to the top-level domain com. The h...
  • How To Add a non-login User in Linux so that he/she doesn't have shell.
    useradd & usermod commands are used to add and modify the users in linux. When invoked without the -D option, the useradd command creat...
  • To Increase Networking Performance Network Stack (Buffers Size)
    By default the Linux network stack is not configured for high speed large file transfer across WAN links. This is done to save memory resour...
  • SVN Server on RHEL6
    Subversion (SVN) is a version control system initiated in 2000 by CollabNet Inc. It is used to maintain current and historical versions of f...
  • Types of NameServer
                                                            There are four primary nameserver configuration:    Master Server:  The primary mast...
  • Apache Security with SELinux
    Security with Apache is an important topic, of which SELinux is a part. The reason for discussing SELInux at this point is so that you have ...
  • How do I hide the Apache version number under Linux server?
    You can easily hide Apche (httpd) version number and other information. There are two config directives that controls Apache version. The S...
  • Configuring ssh Server
                                                          SSH SERVER CONFIGURATIONS ssh command is a client remote login program to connect remo...
  • TOP - Process Activity Command
    The top program provides a dynamic real-time view of a running system i.e. actual process activity. By default, it displays the most CPU-int...

Blog Archive

  • ►  2013 (19)
    • ►  July (1)
    • ►  June (6)
    • ►  May (1)
    • ►  April (11)
  • ▼  2012 (12)
    • ▼  December (11)
      • 20 ways to Secure your Apache Configuration
      • How do I hide the Apache version number under Lin...
      • Apache Security with SELinux
      • SVN Server on RHEL6
      • Displays The Processes
      • Tell How Long The System Has Been Running
      • TOP - Process Activity Command
      • Types of NameServer
      • Configuring ssh Server
      • Domain name formulation
      • lshw command – List hardware information in Linux
    • ►  November (1)
Powered by Blogger.

About Me

Unknown
View my complete profile