Create a new account by useradd command, can't login to the ssh server with new account? - digital-ocean

What happen is i created a new account with useradd command while in root account?
useradd an
then i reboot the cloud server. Try to login with new account an#'ssh-ip' instead of root#'ssh-ip'.
The following error appear.
could not chdir to home directory /home/an: No such file or directory
$ cd
-sh: 10: cd: can't cd to /home/an

You should use adduser instead of useradd to create a new user, see here for details.

Related

Error | entroll the member admin | fabric-ca-client enroll | Amazon Managed Blockchain

I am trying to setup hyperledger fabric blockchain network using amazon managed blockchain following this guide. To entroll, I have used the following command,
fabric-ca-client enroll -u 'https://admin:#D7a22hjjh*9b9#ca.m-zzz.n-zzzz.managedblockchain.us-east-1.amazonaws.com:30002' --tls.certfiles /home/ec2-user/managedblockchain-tls-chain.pem -M /home/ec2-user/admin-msp
I got the following error,
Error: The URL of the fabric CA server is missing the enrollment ID and secret; found 'https://admin:#D7a22613ac75c9b9#ca.m-zzz.n-zzzz.managedblockchain.us-east-1.amazonaws.com:30002' but expecting 'https://<enrollmentID>:<secret>#admin:'
I thought this is due to # symbol in the password. For testing purpose I remove the # symbol and tried. I got the following error.
Error: Failed to create keystore directory: mkdir /home/ec2-user/admin-msp: permission denied
when I use sudo, I am getting the following error,
sudo: fabric-ca-client: command not found
Help me to fix this issue.
What user are you logged in as? whoami
You should be using ec2-user, which has access to the /home/ec2-user/ directory.
You can try manually creating the admin-msp directory before running enrolling the admin:
cd ~ && mkdir admin-msp
Then try running your command.
If that doesn't work, use sudo to create the directory and then chown it to be owned by ec2-user:
cd ~
sudo mkdir admin-msp
sudo chown ec2-user ~/admin-msp
Then try your command.
Note that you can also wrap the username/password in quotes:
fabric-ca-client enroll -u 'https://"admin":"#D7a22hjjh*9b9"#ca.m-zzz.n-zzzz.managedblockchain.us-east-1.amazonaws.com:30002' --tls.certfiles /home/ec2-user/managedblockchain-tls-chain.pem -M /home/ec2-user/admin-msp

Unable to SSH with Keypair

I want to SSH with a new User to my EC2 Instance using Keypair.
1. First I create a new user, a directory in the Home directory and create a new Keypair
sudo adduser Joe --disabled-password
sudo su - Joe
mkdir .ssh
chmod 700 .ssh touch .ssh/authorized_keys
chmod 600 .ssh/authorized_keys
create keypair from the AWS console and saving it on Desktop
2. Using my mac terminal, I am generating the public key
ssh-keygen -y
copy & paste the public key into Vim
vim authorised_keys
pasting the public key in 1 line
in vim using the command :w to paste
in vim command :wq
3. Done with all the set up.. Time to test it:
$ ssh -i "keypair.pem" joe#xx.xxx.xxx.xxx
ERROR
$ joe#xx.xxx.xxx.xxx's password:
What am I doing wrong here - why is it asking me for a password if I have skipped that in the very first step?
If I entered a UNIX Password when creating a the new User, its working all fine and I am able to connect.
I have followed these exact steps: https://aws.amazon.com/premiumsupport/knowledge-center/new-user-accounts-linux-instance/
Appreciate your help.

Run a bash script from another user with Django

this is my first Django project, I apologies if I say some nonsense
To start a game server, I have to login with ssh as the user running the server, then type./server start to start it.
I want to be able to run this command from a webapp.
As of now, I've managed to do this on Django.
What I want to do is that when I press the "Start" button, this commands run on the server side:
su - gameuser -c '/home/gameuser/server start' > /dev/null 2>&1
The problem I'm facing is that I don't know how to login as the gameuser since I'm not a running the webapp as a sudo user.
How can I approach this problem?
Thanks in advance :D
You can configure ssh keys for webapp user to login as gameuser without entering password and execute:
ssh gameuser#localhost -c '/home/gameuser/server start' > /dev/null 2>&1
You can configure webuser to execute specified command with sudo (sudoers file is pretty flexible)
add the following to /etc/sudoers
webapp ALL = (gameuser) ALL
and then you can run the following as webapp user
sudo su - gameuser -c '/home/gameuser/server start' > /dev/null 2>&1
You can improve the second option, allowing webapp user to execute only specific command as gameuser, for example write start script ( /home/gameuser/server_start.sh ) and add to the /etc/sudoers:
webapp ALL = (gameuser) /home/gameuser/server_start.sh
and again you will able to run the following in more secure way.
sudo su -gameuser -c /home/gameuser/server_start.sh

Creating user in ubuntu from AWS

Using AWS (Amazon Web Services) I have created an Ubuntu 16.10 instance and I am able to login using a pem file like this:
ssh -i key.pem ubuntu#52.16.73.14.54
After I am logged, I can see that I am able to execute:
sudo su
(with no password), however the file /etc/sudoers does NOT contain any reference to the user current user: ubuntu.
How can I create another user with exactly the same behavior (without touching the sudoers file) from terminal in a NON interactive way?
I tried:
sudo useradd -m -c "adding a test user" -G sudo,adm -s /bin/bash testuser
But after I become "testuser" if I invoke:
sudo su
I have to provide a password. Which is exactly the way I want to avoid.
You can't do this without touching sudo, beacuse the ubuntu user is given passwordless access specifically.
$ for group in `groups ubuntu`; do sudo grep -r ^[[:space:]]*[^#]*$group[[:space:]] /etc/sudoers* ; done
/etc/sudoers.d/90-cloud-init-users:ubuntu ALL=(ALL) NOPASSWD:ALL
/etc/sudoers.d/90-cloud-init-users:ubuntu ALL=(ALL) NOPASSWD:ALL
/etc/sudoers:%sudo ALL=(ALL:ALL) ALL
But what you can do is create a new sudoers file without touching any existing files. sudo is typically configured these days to read all the configurations in a directiory, usually /etc/sudoers.d/, preceisely so that one failing config doesn't effect the rest of sudo.
In your case, you might want to give an admin group sudoless access rather than your user. Then you can add access in the future to other users without changing sudo config.

login using "ec2-user" instead of root using user data in aws

I have an Amazon EC2 instance based off of a RHEL 6.4 64bit AMI. After writing some shell scripts; I created my own AMI Image off of it.
I'm writing user data section which will remove the contents under /home/ec2-user(sudo rm -rf /home/ec2-user/*) and then execute that script. But i'm unable to remove any files.
what I want:
I want to remove files.
One more weird use case I've, by default user data section enters as "root" user but is there possibility to enter as "ec2-user" user and get my work done..?
User data always runs as root so don't use sudo. Below runs the cmd as ec2-user. If you want to start an executable do so in the background (ie. add & at the end)
su ec2-user -c 'do whatever you want; ./run.sh &'
You cannot do it in the normal ec2-user account Do this command to be the deploy user ...
sudo su - deploy
which will then allow you to go to your app at the current location ...
cd /srv/www/sample_app/current