LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 10-11-2017, 11:29 AM   #1
mnauta
Member
 
Registered: Apr 2003
Posts: 152

Rep: Reputation: Disabled
ssh banner


Hi,

I have an ssh banner set up, but would like to execute a script to show the incoming IP (just because I can, not for any valid security reason)

However the script works form the cli but not if executed by opening an ssh session here are the details.

/etc/ssh/sshd_config
Banner /usr/local/bin/mysshbanner

from cli I get:
mysshbanner
*******************************************
* *
* Welcome! ..... now leave please! *
* *
You are coming in from 192.168.1.33 port 42120
*******************************************


from starting ssh session I get:

ssh manuel@(removed)
#!/bin/bash
echo "*******************************************"
echo "* *"
echo "* Welcome! ..... now leave please! *"
echo "* *"
if [ -n "$SSH_CLIENT" ]
then
set $SSH_CLIENT
echo "You are coming in from $1 port $2"
fi
echo "*******************************************"
manuel@(removed) password:

Any suggested are appreciated.
Thanks
Manuel
 
Old 10-11-2017, 12:35 PM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,292
Blog Entries: 3

Rep: Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718
You could use "ForceCommand" for that. The following probaly works but I have not thought thoroughly about possible pitfalls:

Code:
ForceCommand /usr/local/bin/mysshbanner; sh -c 'if test -n "$SSH_ORIGINAL_COMMAND"; then $SSH_ORIGINAL_COMMAND; else $SHELL; fi'
A different question is whether it is a sound idea.

Last edited by Turbocapitalist; 10-11-2017 at 01:00 PM. Reason: redo sh -c
 
Old 10-11-2017, 04:35 PM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,675

Rep: Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892
One way of doing what you want is adding your code to the /etc/bashrc file. This is the system wide bashrc that is executed when any user logs in.

Code:
if [[ -n "$SSH_CONNECTION" ]]
then
   Echo "Welcome ..."
   set $SSH_CLIENT
   echo "You are coming in from $1 port $2"
fi
Either SSH_CLIENT OR SSH_CONNECTION should work.

Last edited by michaelk; 10-11-2017 at 04:48 PM.
 
Old 10-11-2017, 10:01 PM   #4
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,292
Blog Entries: 3

Rep: Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718
Actually, forget what I wrote in #2 above. michaelk's answer prompts me to remember that the manual page for sshd contains a quiet mention of /etc/ssh/sshrc, which is the global equivalent of ~/.ssh/rc.

Code:
man sshd
You can just put the working parts of your script into /etc/ssh/sshrc and it will run upon login with SSH.
 
Old 10-12-2017, 01:10 PM   #5
lazydog
Senior Member
 
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 1,249
Blog Entries: 3

Rep: Reputation: 194Reputation: 194
I'm watching this thread also as i'm interested in this as well.

The sshrc file works but is only displayed after you have logged in. I too would like to see it displayed with the banner also.
 
Old 10-13-2017, 01:43 AM   #6
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,292
Blog Entries: 3

Rep: Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718
Quote:
Originally Posted by lazydog View Post
The sshrc file works but is only displayed after you have logged in. I too would like to see it displayed with the banner also.
I think that would require modification of the sshd source to add that new function. Currently it just reads a text file for the banner.
 
Old 10-13-2017, 10:19 AM   #7
KenJackson
Member
 
Registered: Jul 2006
Location: Maryland, USA
Distribution: Fedora and others
Posts: 757

Rep: Reputation: 145Reputation: 145
I do a similar thing. But I just use a common .bashrc file that I copy to every machine I have access to. Modifying it to get what you want would be something like this:

Code:
if [ -n "$SSH_CLIENT" ]; then           # Logged in via SSH
    p=${SSH_CLIENT#* }
    echo "You are coming from ${SSH_CLIENT%% *} port ${p% *}"
    unset p
fi
 
Old 10-13-2017, 12:32 PM   #8
lazydog
Senior Member
 
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 1,249
Blog Entries: 3

Rep: Reputation: 194Reputation: 194
Quote:
Originally Posted by Turbocapitalist View Post
I think that would require modification of the sshd source to add that new function. Currently it just reads a text file for the banner.
Yeah, that is the conclusion I'm come too also.
Thanks.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
SSH Banner function raiak Linux - Software 3 03-17-2014 07:53 PM
ssh banner and motd binary_dreamer Debian 4 04-14-2013 06:03 PM
hide ssh banner shafey Linux - Security 3 04-14-2013 05:59 PM
SSH banner design garnser Linux - Software 1 10-16-2004 02:07 AM
change the banner for ssh [cacheflow] Linux - Security 5 09-16-2002 03:03 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:20 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration