Unix and SSH Files From Scratch   Leave a comment

Again I am assuming some Technical/Programming experience. No Unix experience except for my previous post. I am going to cover some default files. As well as how to make you own bash file. I am going to try and explain this through a tutorial on how to add a welcome message to your login.

The first thing you need to do is decide on a message. You could just have a one line message like “Ola welcome to the server” which would be fine.

On the other hand if you really wana go at it. You could get some ascii art or text. Personally I am far from an ascii artist but I have ascii every where. There are a few websites that have ascii fonts. All you have to do is type in what you want and it will write it in ascii for you. http://www.network-science.de/ascii/ was the last site I tried. There are loads out there.

If you have administrative rights on your box creating your welcome msg is easy. If you dont have admin rights thats fine, you can use Option 2  which is also easy.

If you are unsure if you have admin access try and open an editor with admin access if it lets you in, BINGO your admin. Type in sudo pico enter your password when prompted if it lets into the pico editor then you have admin.




Option 1(if you are admin)

There is a file named motd. It is just a text file without the txt file extension. Anything saved in the file will be displayed when you log in.

Step 1 Navigate to your root of your system


Step 2 Navigate to the etc folder


Step 3 Edit the motd file with admin access


Step 4 Type or copy/past your welcome msg in to your editor

Step 5 Save and exit

Now if you log off the server and log in again you should see your msg.


Option 2(if you are on a shared host or if you dont have admin)

So you dont have admin access and you want to trigger something at login. Well what you do is save the msg in a text file then prompt it to be displayed. There is  file that runs every time you log in named .bash_profile. What we will do is create a bash file that when run will display the text from the file. Now this is a bit of a round about way of doing it but it helps cover both bash files and the .bash_profile.

Anything you want to run at login can be added to the .bash_profile file.

A bash file is a Unix file that runs a group of commands. It has a language behind it that contains most of what you would expect if statements, loops, etc. Bash stands for Bourne Again Shell. you can use it to make your server practically do anything.

Step 1 Navigate to your home directory. This is the directory u start in when u log in.

Step 2 Create a new text file called login.txt


Step 3 Assuming you have your msg ready or your ascii if not go get it se the links above.

Step 4 Open the the login.txt file in an editor


Step 5 Past your msg save and exit pico

Step 6 Find the location of you bash


Step 7 Copy the return value it is more than likely this:   /bin/bash   but not necessarily

Step 8 Create a new file in you home directory again which is the bash script


Step 9 Edit the bash script in pico


Step 10 Type in #! then the bash location that you copied in Step 7


Step 11 Type the command that will display the text


Step 12 Save and Exit

Step 13 While still in the root set the permisions for bash file


Step 14 In your home directory edit your .bash_profile so it runs the login bash at login time


Step 15 Add to the bottom of the file the command that runs your bash


Step 16 Save and Exit

Thats all there is. Next time you login you should see your msg. This covers of the basics if you want to know how to write complex scripts there are loads of guides and tutorials to help you on your way out on the interwebs,

Posted May 6, 2011 by abe in Server, ServerSide, ssh, unix

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">