Tag Archives: Command Line

How do I send email from the linux command line?

Need to email from your linux command line? Assuming the underlying pieces are configured correctly (run the 1st example to see) here are the basics…

Send a test email

mail -s "Hi there" [email protected]

Include some body text…

echo "This is some body text" | mail -s "Hi there" [email protected]

Email the contents of a file to someone…

mail -s "My Subject" [email protected] < /path/to/your/file.txt

You can find more here

Please remember to subscribe to the newsletter to stay up to date!

You or someone you know looking to buy or sell?
Disclaimer: Thoughts and opinions are my own, and do not reflect the views of any employer, family member, friend, or anyone else. Some links may be affiliate links, but I don't link to anything I don't use myself. You would think this should be self evident these days, but apparently not...

What timezone is my linux server configured for?

To find out, just run the following command from the shell…

date +%Z
Please remember to subscribe to the newsletter to stay up to date!

You or someone you know looking to buy or sell?
Disclaimer: Thoughts and opinions are my own, and do not reflect the views of any employer, family member, friend, or anyone else. Some links may be affiliate links, but I don't link to anything I don't use myself. You would think this should be self evident these days, but apparently not...

Setting up the ultimate console

If you’ve been coding for any time, chances are you’ve become acquainted with the command line. While some love it and some hate it I think it’s wonderful for getting things done quickly. Unfortunately, the windows command line is crap. With that said I finally got fed up and asked that most important programmer question of “How do I get a better command line”?

That search led me to an open source application called appropriately enough: Console. When I first opened it up and started playing around I have to admit my first reaction was “meh”. Then I asked that import question again, “How can this be made better”? A little Googling and experimentation later I got things working to my satisfaction.

So, here for your one-stop quick-reference is how to setup the ultimate console for Windows…

Assumptions

  • You access the console for all different platforms (not just Windows)
  • You already have putty and its utilities downloaded – and are familiar with their use
  • You already have installed cygwin – and are familiar with its use

Installation

  1. Download Console and extract the contents to the folder of your choice
  2. Download ANSICON and extract the following files to the same directory you extracted Console to.
    • ANSI32.dll
    • ANSI64.dll
    • ansicon.exe

Great, now you have Console installed, but this is the configuration I use to make it really rock.

Configuration

These can all be found under “Edit -> Settings”

  • Appearance
    • Custom color: Change it to an awsome green
  • Appearance -> More…
    • Uncheck “Show toolbar”
    • Select “Alpha” under “Window transparency” and set “Active window” to 25 and “Inactive window” to 40
  • Behavior
    • Check “Copy on select”
    • Uncheck “Clear selection on copy”
  • Hotkeys
    • Set “New Tab 1” to “Ctrl+T”
    • Set “Copy selection” to “Ctrl+C”
    • Set “Paste” to “Ctrl+V”
  • Hotkeys -> Mouse
    • Set “Copy/clear selection” to “None”
    • Set “Select text” to “Left”
    • Set “Paste text” to “Right”
    • Set “Context menu” to “Middle”

Tab Configuration

Now that you have your console looking pretty and being functional, lets hook it into putty and cygwin. You can do this configuration under “Edit -> Settings -> Tabs”. Obviously, the directories you’ve chosen for things will be different (change to your values).

Cygwin: Add a tab and set the shell to:

C:\cygwin\bin\bash.exe --login -i

Putty: Add a tab and set the shell to:

C:\apps\Console2\ansicon.exe "C:\apps\Putty\plink.exe" -load "aSavedSessionName"

Reference

console

 

Please remember to subscribe to the newsletter to stay up to date!

You or someone you know looking to buy or sell?
Disclaimer: Thoughts and opinions are my own, and do not reflect the views of any employer, family member, friend, or anyone else. Some links may be affiliate links, but I don't link to anything I don't use myself. You would think this should be self evident these days, but apparently not...

How to list all environment variables

Often times you can find useful information in your environment variables, but since it’s something you don’t have to do everyday it’s easy to forget. Here’s a refresher:

Windows
First bring up a command prompt, then run the following…

set

To see the value of a single environment variable:

echo %ENVVAR%

Linux
Run the following from a terminal to see all environment variables…

printenv

To see the value of a single environment variable:

echo $ENVVAR
Please remember to subscribe to the newsletter to stay up to date!

You or someone you know looking to buy or sell?
Disclaimer: Thoughts and opinions are my own, and do not reflect the views of any employer, family member, friend, or anyone else. Some links may be affiliate links, but I don't link to anything I don't use myself. You would think this should be self evident these days, but apparently not...

Setup password-less SSH and SCP with public/private keys

Want to scp a file to another server without having to enter the password?  Want to just make your security even stronger?  Public/private keys to the rescue!  Of course, if you don’t know what I’m talking about or why you would want to do this, feel free to google it or just go visit another site.

For those still with me, you need access to both the local and remote servers (duh).  I’m going to refer to the server/host you are logged into as the local machine, and the one you want to connect to as the remote machine.

First, on the local machine you need to generate your public and private keys.  To do so, enter this command…

ssh-keygen -t rsa

Be sure to just hit enter to the questions you’re prompted with (otherwise you will have to enter a password when connecting with the keys – which goes against the whole point of this post).  This will create a couple of files in your .ssh directory (something like id_rsa and id_rsa.pub – your private and public keys respectively). Your public key (the file you want to distribute) ends in “.pub”. Assuming you have that file, send it over to the remote machine (perhaps with scp, yes?)…

scp ./id_rsa.pub [email protected]:/home/user/.ssh/id_rsa.pub

Of course password authentication isn’t enabled yet so you’ll have to enter the password. Next up, you need to login to the remote machine and visit your .ssh directory, and cat the .pub file into your “authorized_keys” file (don’t worry, the command below will create the file if it doesn’t exist. I leave it to you to know how to create the .ssh directory if needed)…

cat id_rsa.pub >> authorized_keys

It’s then a good idea to secure your file and delete the temporary public key on the remote machine…

chmod 600 authorized_keys
rm id_rsa.pub

Once you’ve done all this, you should now be able to connect without a password! Just use your private key…

ssh -i ./id_rsa [email protected]

Have fun!

Please remember to subscribe to the newsletter to stay up to date!

You or someone you know looking to buy or sell?
Disclaimer: Thoughts and opinions are my own, and do not reflect the views of any employer, family member, friend, or anyone else. Some links may be affiliate links, but I don't link to anything I don't use myself. You would think this should be self evident these days, but apparently not...

SSH, SFTP, and SCP on non-standard ports

One common suggestion for securing a secure shell connection on Linux is to change the port that ssh runs on.  But how exactly do you connect to a server on one of these non-standard ports?

Naturally, the syntax is different for each so here goes:

ssh

ssh -p 33432 [email protected]

Yes, ssh uses a lower case p command line argument. Just wait until we get to scp.

sftp

sftp -o "Port 33432" [email protected]

Of course sftp uses a plain English option parameter of “Port XXXX”

scp

scp -P 33432 /home/user/file.txt [email protected]:/home/user

And naturally scp uses a capital P

Gotta love consistency!

Please remember to subscribe to the newsletter to stay up to date!

You or someone you know looking to buy or sell?
Disclaimer: Thoughts and opinions are my own, and do not reflect the views of any employer, family member, friend, or anyone else. Some links may be affiliate links, but I don't link to anything I don't use myself. You would think this should be self evident these days, but apparently not...

Mount a Windows Share in Linux

So you want to access a Windows UNC share in Linux?  No problem if you know the magic commands and have root access.  This can be a great alternative to running cygwin if you are able to access a linux box (directly or via a virtual machine).

First, start by creating your mount point…

sudo mkdir /mnt/share1

Then, actually mount your UNC share to the mount point…

sudo mount -t cifs "//server/share1" /mnt/share -o username=my,password=secret

This would make \\server\share1 available to you on the Linux box as /mnt/share. Note the use of the options parameter (-o) to specify username and password.

Please remember to subscribe to the newsletter to stay up to date!

You or someone you know looking to buy or sell?
Disclaimer: Thoughts and opinions are my own, and do not reflect the views of any employer, family member, friend, or anyone else. Some links may be affiliate links, but I don't link to anything I don't use myself. You would think this should be self evident these days, but apparently not...

Execute a SQL file via the MySQL command line in one line

Have a large script (like a DB dump) you want to execute from the command line in one line so you can just drop it in a batch/shell script and run with it?  Assuming MySql is on your system path, here’s the command…

mysql -u user -ppass < C:\temp\myscript.sql

Where "user" is the username, and "pass" is the password (note, there's no space or other delimiter between the "-p" and the password)

Please remember to subscribe to the newsletter to stay up to date!

You or someone you know looking to buy or sell?
Disclaimer: Thoughts and opinions are my own, and do not reflect the views of any employer, family member, friend, or anyone else. Some links may be affiliate links, but I don't link to anything I don't use myself. You would think this should be self evident these days, but apparently not...

Add a SSL Cert to Your Java Keystore

If you’ve ever had to add a SSL certificate to a java keystore, you know that the command is a little convoluted.  Here for your and my reference is the command…

 "D:\Program Files\Java\jre1.5.0_22\bin\keytool" -import -trustcacerts -alias MyCA2 -file C:\MyCA2.crt -keystore "D:\Program Files\Java\jre1.5.0_22\lib\security\cacerts" 

When promoted for the password, the default is “changeit”, and make sure to choose/type “yes” when asked if you want to trust the cert.

Please remember to subscribe to the newsletter to stay up to date!

You or someone you know looking to buy or sell?
Disclaimer: Thoughts and opinions are my own, and do not reflect the views of any employer, family member, friend, or anyone else. Some links may be affiliate links, but I don't link to anything I don't use myself. You would think this should be self evident these days, but apparently not...