aws ec2 ubuntu require my password - linux

i want to build a project and failed because it requires root permission. When i change the user to root as "sudo -s", it prompted [sudo] password for ubuntu. As ec2 doesn't offer ubuntu password, it login with pem file. How can I login as root and create files? Thanks!

I fixed this by doing using "sudo" for a Ubuntu AWS EC2 SSH Login:
$ sudo passwd ubuntu
Instead of prompting me for:
"(current) UNIX password:"
It prompts now for:
"Enter new UNIX password:"
I hope this fixes some problems with ec2 ubuntu users!

I was surprised as well, when AWS ec2 ubuntu prompted me for a password.
[sudo] password for ubuntu:
In the end I just hit return without inserting anything and it worked.

If you want to run commands from your terminal interactively as root do it as follows:
sudo -i
If just want to run a single command do it as:
sudo some-command-goes-here
You will not be prompted for password in any of these scenario.

AWS doesn't grant root access by default to EC2 instances. This is an important security best practise. Users are supposed to open a ssh connection using the secure key/pair to login as ec2-user. Users are supposed to use the sudo command as ec2-user to obtain elevated privileges.

Related

Google Compute Engine instance requires password for sudo - what is my password?

I have a new google compute engine instance. I am SSH'ed into the instance using certs. Whenever I try to use sudo it asks for the primary user's password which I do not have. Just recently I setup an instance on centos 7 and did not have this issue.
The instance is running centos 8. Normally, I would ssh to the instance, then execute commands using Sudo. For example, I would like to set the root password.
if I run sudo passwd, sudo su - or even sudo cat /var/log/messages it asks me for the primary user's password. The problem is I do not have that password.
[primaryuser#server4 log]$ **sudo cat messages**
**[sudo] password for primaryuser:**
##########
[primaryuser#server4 log]$ **sudo passwd**
**[sudo] password for primaryuser:**
I expected to run the commands using sudo but do not have the password.
Does anyone have any ideas? I read other posts about similar problems but different from mine.
I had to give up and use ubuntu. Everything acted as expected on ubuntu and I was able to set the password. I believe the problem is limited to centos 8 but I am not certain.

Cannot switch to jenkins user on aws ec2 linux?

When I ssh into an aws ec2 Linux instance, I am ec2-user. The instance is a Jenkins master. When I try su - jenkins and entered the correct password, the system says Last login: .... which looks like the switching succeeded. But whoami says I'm still ec2-user.
What am I missing? Thanks!
jenkins is a service account, it doesn't have a shell by design. It is generally accepted that service accounts shouldn't be able to log in interactively.
if you really want to login as Jenkins, you can do so with: sudo su -s /bin/bash jenkins

How do I set my user password on my Google Cloud Ubuntu instance?

I have started an Ubuntu 15.10 instance on Google Cloud and installed Webmin as per here:
http://www.webmin.com/deb.html
Webmin has been installed successfully and I can see the login page in my browser window, however I need to type my username along with my password with sudo level access to login and start using Webmin.
I've used the SSH via the browser window so have never set a password for any sort of access to the root.
Does anyone know how to set a password for myself to login as a sudo user on my instance?
Okay, I figured it out. I was looking at the permissions menu in Google Cloud, but it was as simple as changing the root password in Linux by typing: sudo passwd
it's working for me
vfa_gianglt#instance-1:~$ sudo -i
root#instance-1:~# sudo bash
root#instance-1:~# sudo passwd root
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
root#instance-1:~# cd /root
root#instance-1:~#

Is it possible to connect to ec2 instance as root user by using the PEM file?

I'm trying to connect to an EC2 AWS instance but when I tried to install PHPMYADMIN the linux console asks me for the root user password, which I forgot about. Could anyone please know how to use .PEM file to login as the root user?
I tried sudo su command but it still asks me for the root user.
Any help is appreciated.
Disclaimer: It is not recommended to login as root.
But still if you want to, then:
Allow PermitRootLogin in /etc/ssh/sshd_config
Restart SSH service
you need to paste the existing public key which is in the /home/ec2-user/.ssh/authorized_keys to /root/.ssh/authorized_keys
Now you should be able to login as root using the .pem key.
You don't need your root password if you are running sudo su -, you need the password of the user you are running the sudo command as. Provided that the user has sudo privileges as root. Then you can just run as root:
yum install phpmyadmin

Amazon EC2 - Prompted for Password when Switching to Passwordless User

Some background ...
I've just started using Amazon EC2 and I have a question regarding users and passwords.
As you surely well know, the default user (which in the case of Ubuntu Server 12.04 LTS is named ubuntu) doesn't have a password but instead uses public-private key authentication to login.
For reference, here's the contents of my /etc/sudoers.d/90-cloudimg-ubuntu file:
# ubuntu user is default user in cloud-images.
# It needs passwordless sudo functionality.
ubuntu ALL=(ALL) NOPASSWD:ALL
My question ...
I've since created a second user named jdoe who is a member of the admin group. The user jdoe has a password as well as a public-private key pair.
When logged in as jdoe I try to switch to the default ubuntu user using the following command, but I'm unexpectedly prompted for a password. How come? The user ubuntu (afaik) doesn't have a password!
jdoe#host:~$ su ubuntu
Password:
Thanks in advance for your help and comments!
su and sudo are 2 different things and you're getting confused.
When you login as ubuntu and run any command using sudo, it will not ask for password because of ubuntu ALL=(ALL) NOPASSWD:ALL
Now jdoe is a part of admin group but admin groups needs to provide password as per %admin ALL=(ALL) ALL. This statement is found by running visudo. Please note that this statement does not have NOPASSWD:ALL
So when user jdoe runs any command as sudo, he has to enter the password
Now, su is entirely different aspect thansudo. And when you run su ubuntu, there is no sudo thing in picture. So it will ask you for the password of user ubuntu.
In otehrwords, the statement jdoe#host:~$ su ubuntu is asking you to enter the password of user ubuntu. As you do not have password for ubuntu set, this will never succeed.
However, if you login as ubuntu and try sudo su jdoe, it will not ask for any a pssword. But.... if you login as ubuntu and run su jdoe, it will ask you for the password of user jdoe. Try this so you get better understanding around how it works.

Resources