Showing posts with label AWS. Show all posts
Showing posts with label AWS. Show all posts

Saturday 8 June 2019

AWS SSH and SFTP Disconnected: No supported authentication methods available (server sent: publickey)

Disconnected: No supported authentication methods available (server sent: publickey)

Could not connect to server

Step 1 : Login aws console
Step 2 : Go to instance list
Step 3 : Stop instance which have issue
Step 4 : After stop instance, Click and open "View/Change User Data" (See image)



Step 5 : Add Following code into textarea
 Content-Type: multipart/mixed; boundary="//"
MIME-Version: 1.0
--//
Content-Type: text/cloud-config; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="cloud-config.txt"
#cloud-config
cloud_final_modules:
- [scripts-user, always]
--//
Content-Type: text/x-shellscript; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="userdata.txt"
#!/bin/bash
ls -Al
ls -Al /home
ls -Al /home/ubuntu
ls -Al /home/ubuntu/.ssh
sudo cat /home/ubuntu/.ssh/authorized_keys
chown root:root /home
chmod 755 /home
chown ubuntu:ubuntu /home/ubuntu -R
chmod 700 /home/ubuntu
chmod 700 /home/ubuntu/.ssh
chmod 600 /home/ubuntu/.ssh/authorized_keys
ls -Al
ls -Al /home
ls -Al /home/ubuntu
ls -Al /home/ubuntu/.ssh
sudo cat /home/ubuntu/.ssh/authorized_keys
sudo ufw disable
sudo service sshd restart
--//
Step 6 : Click on save button
 Step 7 : Finish! Check your SSH and SFTP detail

Friday 8 March 2019

How to create CloudFront Distributions / CDN in AWS with Origin EC2 / Loadbalancer

Origin Settings

Step 1 : Login AWS console ( https://console.aws.amazon.com )
Step 2 : Open CloudFront console ( https://console.aws.amazon.com/cloudfront/ )
Step 3 : Click on "Create Distribution" 
Step 4 : Click on "Get started" on Web
Step 5 : "Origin Domain Name" = Select your load balancer for EC2 
Step 6 : Origin Path = Blank (add cdn file directory path if specific dir add for CDN )
Step 7 : Origin SSL Protocols = default selection
Step 8 : Origin Protocol Policy = HTTP Only
Step 9 : Origin Response Timeout = 30 (default) 
Step 10 : Origin Keep-alive Timeout = 5 (default)
Step 11 : HTTP Port = 80  (default)
Step 12 : HTTPS Port = 443 (default)
Step 13 : Origin Custom Headers = Blank (like default) 

Default Cache Behavior Settings 

Step 14 : Viewer Protocol Policy = HTTP and HTTPS
Step 15 : Allowed HTTP Methods = GET, HEAD
Step 16 : Field-level Encryption Config = blank (default)
Step 17 : Cache Based on Selected Request Headers = None (default)
Step 18 : Object Caching = Use Origin Cache Headers (default)
Step 19 : Forward Cookies = None (default)
Step 20 : Query String Forwarding and Caching = None (default)
Step 21 : Smooth Streaming = No (default)
Step 22 : Restrict Viewer Access (Use Signed URLs or Signed Cookies) = No (default)
Step 23 : Compress Objects Automatically = No (default)
Step 24 : Lambda Function Associations = (default)

Distribution Settings

Step 25 : Price Class = Use U.S., Canada, Europe, Asia and africa (You can select ALL for best performance world wide)
Step 26 : AWS WAF Web ACL = None (default)
Step 27 : Alternate Domain Names (CNAMEs) = Subdomain like cdn.jaydipkansagra.com (you can add multiple domain here)
Step 28 : SSL Certificate = Select custom if you want SSL on cdn url ( If option disable you need to create Certificates into N.Virginia ) 
Step 29 : Supported HTTP Versions = HTTP/2, HTTP/1.1, HTTP/1.0
Step 30 : Default Root Object = Blank (default)
Step 31 : Logging = Off (default)
Step 32 : Enable IPv6 = Checked (default)
Step 33 : Comment = Blank (default)
Step 34 : Distribution State = Enabled (default)
Step 35 : Click on Create Distribution button (default)

Pointout domain 

Step 36 : Point subdomain cdn.jaydipkansagra.com to d111111abcdef8.cloudfront.net
Step 37 : open the Route 53 console at https://console.aws.amazon.com/route53/
Step 38 : Click Hosted Zones
Step 39 : Click Create Record Set
Step 40 : Name = cdn, Type = CNAME, Alias = NO, TTL (Seconds) = 300, Value = d2m9sh2v6fo5gb.cloudfront.net
Step 41 : Click on save button
Step 42 : Finish : Open http://cdn.jaydipkansagra.com thats done

Friday 21 December 2018

How to create snapshot and attach with another instanse

  1. Stop current instanse
  2. Create new Snapshot (Please check volume properly) from current volume
  3. Create new instanse with greter or equal to current volume (GB) from old instanse
  4. Stop New instanse
  5. Goto spanshot and create volume with (us-east-1d)
  6. Goto volume and detach currnet volume of new instanse
  7. attach new volume which you have created from snapshot (us-east-1d) make sure same root (/dev/sda1)
For your ref : https://www.youtube.com/watch?v=W89C_OqlOwE

Saturday 17 November 2018

Mysql usage grater than 100% of CPU in ubuntu 18.04 | 16.04 in AWS

 You need to update server configuration.

1. Open terminal
2. Put command : sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf




3. Find following variables
key_buffer_size         = 16M
max_allowed_packet      = 16M
thread_stack            = 192K
thread_cache_size       = 8
query_cache_limit      = 1M
query_cache_size        = 16M
Change To
key_buffer_size         = 160M
max_allowed_packet      = 160M
thread_stack            = 1920K
thread_cache_size       = 80
query_cache_limit       = 1024M
query_cache_size        = 2048M
4. Restart mysql : sudo /etc/init.d/mysql restart
5. Restart apache2 sudo systemctl restart apache2
6. Check CPU usage : ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%cpu | head
 For more Information please Refer : https://dev.mysql.com/doc/refman/5.7/en/server-configuration.html

Thursday 11 October 2018

How to redirect www to non www AND http to https in AWS .htaccess


AWS WWW to non WWW redirection
RewriteEngine On
RewriteCond %{SERVER_NAME} =www.example.com
RewriteRule ^.*$ https://example.com%{REQUEST_URI}
AWS HTTP to HTTPS redirection
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^.*$ https://example.com%{REQUEST_URI}
AWS WWW to non WWW and HTTP to HTTPS
RewriteEngine On
RewriteCond %{SERVER_NAME} =www.example.com
RewriteRule ^.*$ https://example.com%{REQUEST_URI}
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^.*$ https://example.com%{REQUEST_URI}

Tuesday 29 May 2018

How to force redirect HTTP to HTTPS in AWS or any other server using .htaccess

1st Method
<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteRule .* https://%{HTTP:Host}%{REQUEST_URI} [L,R=permanent]

RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

2nd Method
<IfModule mod_rewrite.c>
     RewriteEngine On
     RewriteCond %{HTTPS} !on
     RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>

Saturday 13 January 2018

How to install custom or subdomain SSL certificate in AWS.

How to install custom or subdomain SSL certificate in AWS.

1. sudo dpkg –s openssl

2. sudo a2enmod ssl

3. sudo service apache2 restart

4. openssl req -nodes -newkey rsa:2048 -keyout myserver.key -out server.csr
1. Country Name (2 letter code) [AU]: GB
2. State or Province Name (full name) [Some-State]: Surrey
3. Locality Name (eg, city) []: London
4. Organization Name (eg, company) [Internet Widgits Pty Ltd]: Company Name Pvt Ltd
5. Organizational Unit Name (eg, section) []: IT Department
6. Common Name (eg, YOUR name) []: yourdomain.com
7. Email Address []:webmaster@yourdomain.com
8. A challenge password []:
9. An optional company name []:

5. GET Certificate files and upload to "/var/www/html/cert/" :
1. private.key - Which you have generate using step 4
2. c00d2e98b15a0818.crt - Which you get certificate 3rd party
3. gd_bundle-g2-g1.crt - Which you get chain 3rd party

6. sudo nano /etc/apache2/sites-available/default-ssl.conf
**************
**************
DocumentRoot /var/www/html
<Directory /var/www/html/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
*******
*******
*******
SSLCertificateFile "/var/www/html/cert/c00d2e98b15a0818.crt"
SSLCertificateKeyFile "/var/www/html/cert/private.key"
SSLCertificateChainFile "/var/www/html/cert/gd_bundle-g2-g1.crt"
*******
*******
*******

7. sudo a2ensite default-ssl.conf
8. sudo service apache2 restart
9. Check your ssl : https://www.sslshopper.com/ssl-checker.html