I am assuming you have already setup PuTTY for AWS access. If haven’t yet, please follow the instructions at Setting up PuTTY for AWS access. Also, obviously, you need to have an AWS Instance setup. If you haven’t setup an AWS Instance, you can find help at “Setting up a Free Tier Amazon EC2 Instance.”
These instructions assume you have already installed WinSCP on your computer. If you need WinSCP, it can be found at www.winscp.net. It is really easy to install on windows machines.
Configuration for AWS Instance access
You need to access your AWS dashboard as well as WinSCP.
- Open your AWS Console (go to http://aws.amazon.com and login)
- Go to “EC2” under “Compute and Networking”
- Click on “Instances” under the “Instances” section of the Navigation pane. This will display all of the instances you currently have running. Clicking on the name of the instance will show the details of that instance below. Select the instance you want to configure WinSCP for then find the “Key Pair Name” and “Security Groups” values under the “Description” tab. If you haven’t already done so for PuTTY, you will need to edit the security group in order to allow an SSH client (WinSCP in this case) to access your instance then confirm the security key with the key pair name.
- Find the value for “Public DNS” under the “Description” tab then highlight it (shift+ left click while selecting the text) and press CTRL+C to copy the text. You will need this value when setting up WinSCP and I find copy & pasting a whole lot easier than retyping something.
- Click on “Security Groups” under the “Networking & Security” section of the Navigation pane. This will show your security groups for this region. Click on the instance’s security group to see the details of that group.
- Click on the “Inbound” tab to edit the firewall associated with this security group.
- SSH clients use port 22 for access, so you will need to verify that TCP port 22 (SSH) is listed on the table to the right. If it is not listed, or there is no table, select “SSH” under for “Create a new rule” then add your computer’s ip address to the source line followed by “/32”. AWS security groups use CIDR notation for IP address ranges. Simply, “/32” limits the range to a single IP address. Click “Add Rule” then click “Apply Rule Changes”
- Click on “Key Pairs” under the “Networking & Security” section of the Navigation pane. The “Fingerprint” for the “Key Pair Name” will be needed later to confirm your connection to the AWS Instance.
- Open WinSCP.
- Click on “New” to add a new session. Note, if this is the first time you’ve used WinSCP, you will automatically be prompted for a new session.
- Choose “SCP” as the “File protocol”
- Choose “22” for “Port number”. Note, you can actually use a different port than the default 22 to connect with the AWS Instance. You would have to make the appropriate adjustments to the ssh shell and the AWS Security Group. This can be good from a security standpoint, but is extremely risky from a setup standpoint. If you mess up the settings you will be permanently locked out of SSH access to the instance, generally making it worthless.
- Paste your instances’ “Public DNS” value in the “Host name” box.
- Enter “ec2-user” as the “User name” and leave the “Password” box blank..
- Click on the “…” button in the “Private key file” box and open your private key that corresponds to the Key Pair Name” you generated when setting up the instance. This was the same file you opened in the PuTTYGen program earlier.
- Click “Save”. There’s no point in reentering this info every time you want to login.
- The first time you log in you will get a security fingerprint confirmation. This value should be the same as the one provided through the AWS console.
- Click “Login”. This will log you in as the ec2-user user. This is fine for some stuff, but you won’t be able to change to the root user without completing the last few steps.
- Open the file “/etc/sudoers”
- Find the line “Defaults reguiretty” and add “Defaults:ec2-user !requiretty” as the next line. This will allow WinSCP to transfer itself to the root user after logging on by using sudo su, just like in PuTTY.
- Disconnect. The disconnect option can be found under the “Sessions” menu.
- Click on the session you just created then click “Edit”
- Click on “SCP/Shell” on the left options. Note, “SCP/Shell” isn’t listed under “Environment” check the “Advanced options” box at the bottom to display the option.
- For “Shell:” select “sudo su -” as the option. Make sure “Return code variable” is set to “Autodetect”.
- Click “Save”
When you log in, your shell access will automatically be changed to the root user allowing for complete access to all files. For most web development activities, root access isn’t needed, however it makes life easier AND is essential for installing and configuring most of the software.