I am new to this AWS.
I launched one EC2 instance and used cygwin to do the stuff, everything is working I launched the EC2 machine, I am able to :
But once I stop the instance and starts it again, it does not allow me to login as root?
First of all, the IP gets changed every time I stops and starts the machine.
Secondly, why once machine starts again after being stopped, the command : ssh -i pem.file root@ip shows following message:
Please shed some light.
It is because the AMI you used to launch the instance does not permit root login over SSH. What kind of Linux instance did you launch?
You can change that in /etc/ssh/sshd_config
and the option would be PermitRootLogin yes
(make sure to restart the sshd
service). However, in order for the .pem
key file to work, you'd have to setup the public key to work for root
. The quick way to do that is to copy /home/cloud-user/.ssh/authorized_keys
to /root/.ssh/authorized_keys
. However, this is not a recommended practice.
The Please login as the user "cloud-user" rather than the user "root".
message you are getting is because of the command
option in the /root/.ssh/authorized_keys
.
As for the public IP of the instance, that's because your instance is what's called EC2 Classic. If you want the public IP to persist you will have to launch the instance in a custom VPC with an Internet Gateway and attach an Elastic IP to it. This is a good guide.
Did you install the cloud-init
RPM? The cloud-init
RPM for the CentOS AMI creates a user named cloud-user
but without the requisite sudo
privileges. So after a reboot there's no way to sudo
or do anything meaningful.
To fix this issue, launch a vanilla CentOS instance, install the cloud-init
RPM, but before rebooting, modify /etc/cloud/cloud.cfg
to grant sudo privileges for cloud-user
.
default_user:
name: cloud-user
gecos: Cloud user
groups: [wheel, adm]
sudo: ["ALL=(ALL) NOPASSWD:ALL"]
shell: /bin/bash
The sudo
privileges of cloud-user
will now survive a reboot. Alternatively you can retain root access as show here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With