Jeremy  Reilly

Jeremy Reilly


Remotely Execute Amazon EC2 Linux Commands without SSH

While working with various cloud providers in my software engineering role at DLT Labs, I came across a very useful technique, which we can leverage to run commands or scripts on Amazon Web Services (AWS) virtual machines — EC2 instances — without requiring SSH access and without allowing any port access.

I will be using a service called AWS System Manager to achieve this.

AWS System Manager (SSM) is one of the many popular AWS services which help you easily run remote commands or scripts on one or more EC2 machines.

In this blog, I’m going to share how we can do this using AWS SDK NodeJS.


During code implementation, our goal will be to execute the following commands on EC2 machine by using AWS SSM:

  • Touch sample.txt
  • Echo I am from target machine >> sample.txt
  • Ls
  • Cat sample.txt

Additionally, we will learn how to see the command status and corresponding logs on the application server.


The readers are expected to have some knowledge about Amazon AWS, example, they should know about IAM roles, IAM users, and how to attach roles to EC2 Instances. Apart from that I will be using NodeJS tech stack. Details of both have been described below:

1. Configurations and policies that are needed.

  • **IAM User’s credentials: **Create an IAM user and attached EC2 and SSM policies to that user so that it will able to execute the commands on target machines.
  • IAM Role: Create a new IAM role and attach the AWSEC2RoleforSSM policy to it. All the target machines should have this role attached to them so that SSM service will be able to communicate with the EC2 machines.

2. Software/libraries

  • NodeJS engine
  • AWS-SDK module: To install this module, use: npm i aws-sdk
  • Bluebird: use npm i bluebird
  • Lodash: use npm i lodash

>> The code implementation will take place in the following stages:

  1. Before sending commands to the target machine, first we will check whether the target machine is ready for receiving the commands.
  2. If the machine is ready, then we will send the commands.
  3. After that, we will continuously monitor the command status.
  4. Once the command gets executed, we can see their logs in the console of the remote machine.

All set, let’s begin with the actual code implementation.

#productivity #javascript #business #programming #dltlabs

What is GEEK

Buddha Community

Remotely Execute Amazon EC2 Linux Commands without SSH

Examples of the dig command in Linux

Dig Command Line Options and Examples
Here is the frequently used command line options and example’s of dig command.
1. Basic Dig Command
A basic dig command accept domain name as command line parameter and prints Address record.
2. Query With Specific DNS Server
The default dig command queries to dns server configured on your system. For example, the Linux systems keep default DNS entry in /etc/resolv.conf.
3. Print Short Answer
Use +short command line option to print result in short form. This is basically useful with the shell scripting and other automation tasks.
4. Print Detailed but Specific Result
Use +noall with +answer to print detailed information but specific. This will print only answer section including few more details as a result.

#linux commands #command #dig #dig command #useful examples #linux

Useful Example for the mv command in Linux

mv Command Examples
Below is the basic mv command examples on Linux terminal.

  • Rename file in current directory – For example rename file source.txt to dest.txt in current directory.
  • Move file to destination directory – Move a source.txt file available in current directory to /tmp directory. In above command the file name is unchanged at target directory. You can also rename file name at destination directory just by providing filename at destination.
  • Move file from source directory to destination directory – We can also move files or directory from some other directory to destination directory.
  • Move multiple files to destination at once – The mv accepts multiple source files and move them to the destination directory at once. The following command will move file1.txt, file2.txt in current directory and /opt/file3.txt to the /tmp directory. Here the last command line parameter is used as destination by the mv command.

#linux commands #command #mv #useful example #mv command #linux

How to Force cp Command to Overwrite without Confirmation

The cp command (which stands for a copy) is one of the commonly used commands on Linux and other UNIX-like operating systems, for copying files and directories. In this guide, we will show how to force the cp command to overwrite a copy operation without confirmation in Linux.

Related Article10 SCP Commands to Transfer Files/Folders in Linux

Usually, when you run a cp command, it overwrites the destination file(s) or directory as shown.

## cp bin/ test/

To run cp in interactive mode so that it prompts you before overwriting an existing file or directory, use the -i flag as shown.

## cp -i bin/ project1/

By default, modern Linux distributions especially those in the Red Hat Enterprise Linux (RHEL) family come with an alias for the cp command which makes a user run the cp command in interactive mode. This may not be the case on Debian and Ubuntu derivatives.

To check all your default aliases, run the alias command as shown.

## alias

View All Linux Aliases

#linux commands #cp command examples #linux tricks #linux

Arvel  Parker

Arvel Parker


How to Use the Screen Command in Linux

Screen is a terminal program in Linux which allows us to use a virtual (VT100 terminal) as full-screen window manager which multiplexes an open physical terminal between multiple processes, which are typically, interactive shells. It allows us to access multiple terminal sessions within a single terminal or a remote terminal session. It is most useful when addressing multiple Linux shell commands on the command line, as well as separating commands from the shell that started the commands.

Screen also allows a user to initiate a command from one terminal, disconnect from that terminal, and then reconnect from a different location to that same terminal, while using a different terminal without having to restart the command. This simply lets a user better control multiple and separate command windows.

Screen also lets multiple remote computers connect to the same screen session at once. This allows multiple users to connect to the same screen session allowing a second user to follow along with another administrator working on a server.

#tutorials #attach #cli #command line #detach #key bindings #logging #multiplex #multiuser #multiuser mode #remote access #remote management #remote session #remote terminal #screen #screen logging #screen session #screenlog #screens #scrollback #shell #terminal #terminal session #terminal window #tty #vt100

date command in Linux with Examples

date Command Examples
Show date time in UTC/GMT
View past dates on specific days
View future dates
View date in other timezone
Print date in specific format
View file modification time

#linux commands #command #date #linux