Connecting to EC2 servers from Mac using shortnames

If you have to connect to a number of EC2 machines, typing a long command that looks like the following each time can be painful.

ssh -i  /somepath/somefile.pem   someuser@someserver.compute-1.amazonaws.com

A way to make this command much shorter is by using SSH config file.

Edit (or create) file ~/.ssh/config

vi ~/.ssh/config

Now for each EC2 server that you connect to, add a section that looks like this…

Host test1
HostName 100.100.100.100
User ec2-user
IdentityFile /User/name/ec2pems/test1.pem

Now you can connect to the instance by typing a command that looks like this…

ssh test1
Advertisements

Linux: How to make a foreground process run in background

So you started a process on a remote server. The job is now running in an SSH window and is taking longer than you thought it would. If you close the SSH window, it will kill the process. There is a way by which you can close the SSH window by sending the process to background.

Go to the window where the process is running and type the following commands

> CTRL+Z
> bg

To bring the process back to foreground, use the commands job and fg

Get a list of all the background jobs and then pass the job number to fg

> jobs
> fg [job num]

This works well on Fedora, RedHat and CentOS.