LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-21-2015, 07:37 AM   #1
Ali3n0id
LQ Newbie
 
Registered: Nov 2014
Distribution: Mint, Raspbian, Ubuntu 14
Posts: 24

Rep: Reputation: Disabled
Custom SSH Banner with script


Hi all,

I want to create a SSH header for all my servers that will include some scripts.

For example it will display internal and external IP as well as memory usage.

I understand that you must edit the /etc/motd file to do this.

I have edited mine:

Code:
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.

Current external IP: "$IP_SCRIPT"
I am new to scripts and wonder what's the process of getting this script to work

The IP_SCRIPT for example will use the curl -s and ifconfig commands to output results to the banner
 
Old 02-21-2015, 09:42 AM   #2
pingu
Senior Member
 
Registered: Jul 2004
Location: Skuttunge SWEDEN
Distribution: Debian preferably
Posts: 1,350

Rep: Reputation: 127Reputation: 127
I don't know if you can run a script from /etc/motd, but here's what I've done to achieve the same thing:
Basically, just call a script from users ~/.bashrc, it will print out when they login.
I always create a custom file "/tux/conf/profile/bash.sh" which is sourced from ~/.bashrc - this is because I want to keep all custom configuration in my own directory-structure, away from system.

Below is my "/tux/conf/profile/bash.sh", with some basic config and a script that is used for servers using "ucarp" - that is they share one virtual up and the one that holds that ip is the "live" web-server.

Code:
# Script to check for virtual ip, and server status
# But only for login shell

# Default prompt
PS1="[\u@\H:\w]$ " 

# Custom aliases
alias l='ls -la'

# PATH for sudo-users 
export PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin:ih/sbin

# Script to check server status
# But only for login shell
case "$-" in *i*)    # This is the line that makes this script run only for login-shells
        if [[ $(ip addr show eth0 |grep "10.64.6.8") ]]; then
                echo -e "This server is \e[01;31m MASTER \e[0m"
        else
                echo "This server is Standby"
        fi
        echo ""
esac
 
Old 02-21-2015, 11:18 AM   #3
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,608

Rep: Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960
Quote:
Originally Posted by Ali3n0id View Post
Hi all,
I want to create a SSH header for all my servers that will include some scripts. For example it will display internal and external IP as well as memory usage. I understand that you must edit the /etc/motd file to do this.

I have edited mine:
Code:
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.

Current external IP: "$IP_SCRIPT"
I am new to scripts and wonder what's the process of getting this script to work The IP_SCRIPT for example will use the curl -s and ifconfig commands to output results to the banner
Look at the ForceCommand option in sshd_config:
http://linux.die.net/man/5/sshd_config

It *MAY* do what you're after, but use sparingly. If I remember correctly, I tried this once, and it DID let me execute things upon login, but it negated what I tried to do from the command line. For example, just logging in, things worked fine. If you tried doing "ssh user@host "/some/script.sh"", then the results may not be right...since you're FORCED to run one script first, before ANYTHING else.
 
Old 02-24-2015, 12:48 PM   #4
ron7000
Member
 
Registered: Nov 2007
Location: CT
Posts: 248

Rep: Reputation: 26
might be slightly different on your system, i use Suse (opensuse and SLES).
look in file etc/ssh/sshd_config
for #Banner
uncomment it and do something like "Banner /etc/ssh_banner.txt"
where /etc/ssh_banner.txt is what you want displayed as a banner.

for executing script after logon,
in suse at the end of the /etc/bash.bashrc file which gets executed during logon there is
Code:
# And now let us see if there is e.g. a local bash.bashrc
# (for options defined by your sysadmin, not SuSE Linux)
#
case "$is" in
bash) test -s /etc/bash.bashrc.local && . /etc/bash.bashrc.local ;;
ksh)  test -s /etc/ksh.kshrc.local   && . /etc/ksh.kshrc.local ;;
zsh)  test -s /etc/zsh.zshrc.local   && . /etc/zsh.zshrc.local ;;
ash)  test -s /etc/ash.ashrc.local   && . /etc/ash.ashrc.local
esac
test -s /etc/sh.shrc.local && . /etc/sh.shrc.local
in /etc/bash.basrc.local and csh.cshrc.local is where i had all my admin stuff, in one spot.
I would put a call to whatever you want to happen in there.

one thing i always hated and never found out, is what the chronological process is when you log on to linux and whether distributions differ. after your password is accepted, then I know files like /etc/bash.bashrc and /etc/profile are sourced, and further things get run like if remote desktop and graphics like gdm and xdm are kicked off. But i would love to know that process in detail.
 
Old 02-24-2015, 12:55 PM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,786

Rep: Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304
that case is not necessary:
Code:
test -s /etc/$is.${is}rc.local && . /etc/$is.${is}rc.local
will do the job
 
Old 03-16-2015, 12:31 PM   #6
Ali3n0id
LQ Newbie
 
Registered: Nov 2014
Distribution: Mint, Raspbian, Ubuntu 14
Posts: 24

Original Poster
Rep: Reputation: Disabled
Thank you all very much - the ForceCommand was exactly what I needed.

Now to customise this script to insanity.
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] custom login script for *shared account* (using SSH) gnuweenie Linux - Security 3 03-03-2011 02:08 PM
Login Warning Banner or Greeter /etc/gdm/custom.conf johnmccarthy Linux - Newbie 2 08-03-2010 08:30 PM
[SOLVED] Script to generate SSH Banner MOTD geforce Programming 6 04-18-2010 04:26 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 - Software

All times are GMT -5. The time now is 03:46 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