How do I create a user and add an SSH key on an EC2 instance?Why do I get “Permission denied (publickey)”...
How can a new country break out from a developed country without war?
Does the Shadow Magic sorcerer's Eyes of the Dark feature work on all Darkness spells or just his/her own?
How old is Nick Fury?
How to balance a monster modification (zombie)?
Can "few" be used as a subject? If so, what is the rule?
Why do I have a large white artefact on the rendered image?
When did hardware antialiasing start being available?
What will the Frenchman say?
Are hand made posters acceptable in Academia?
Nested Dynamic SOQL Query
Should a narrator ever describe things based on a characters view instead of fact?
I got the following comment from a reputed math journal. What does it mean?
Why is participating in the European Parliamentary elections used as a threat?
Did Nintendo change its mind about 68000 SNES?
What is it called when someone votes for an option that's not their first choice?
Was World War I a war of liberals against authoritarians?
Would mining huge amounts of resources on the Moon change its orbit?
Friend wants my recommendation but I don't want to
Imaginary part of expression too difficult to calculate
Is xar preinstalled on macOS?
Why is this tree refusing to shed its dead leaves?
Turning a hard to access nut?
Knife as defense against stray dogs
Pre-Employment Background Check With Consent For Future Checks
How do I create a user and add an SSH key on an EC2 instance?
Why do I get “Permission denied (publickey)” when trying to SSH from local Ubuntu to a Amazon EC2 server?ssh-agent forwarding and sudo to another userSudo as different user and running screen“Add correct host key in known_hosts” / multiple ssh host keys per hostname?how do you create an ssh key for another user?AWS - removing ec2-user from sudo listHow to ssh into ec2 instance running centos as a newly created user?SSH login fails for EC2 instances created from image of working EC2How does Amazon ec2-user get its sudo rightscan' t access ec2 instance for additional user with sftp or ssh - key refused
I can ssh
into a remote EC2 instance with ec2-user
and the keypair in the EC2 account with root(sudo) privileges.
How can I manually create another non-ec2-user user account, add an SSH key, and add sudo
permissions to that user?
linux ssh amazon-ec2 sudo ssh-keys
add a comment |
I can ssh
into a remote EC2 instance with ec2-user
and the keypair in the EC2 account with root(sudo) privileges.
How can I manually create another non-ec2-user user account, add an SSH key, and add sudo
permissions to that user?
linux ssh amazon-ec2 sudo ssh-keys
add a comment |
I can ssh
into a remote EC2 instance with ec2-user
and the keypair in the EC2 account with root(sudo) privileges.
How can I manually create another non-ec2-user user account, add an SSH key, and add sudo
permissions to that user?
linux ssh amazon-ec2 sudo ssh-keys
I can ssh
into a remote EC2 instance with ec2-user
and the keypair in the EC2 account with root(sudo) privileges.
How can I manually create another non-ec2-user user account, add an SSH key, and add sudo
permissions to that user?
linux ssh amazon-ec2 sudo ssh-keys
linux ssh amazon-ec2 sudo ssh-keys
asked 3 mins ago
Jamieson BeckerJamieson Becker
770712
770712
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Create the user account
First,. create the user account using the standard Linux/UNIX useradd
command:
NEWUSER='newusername'
SSHPUBKEY='ssh-ed25519 AAAA..xyz jamieson@desktop'
sudo useradd -m $NEWUSER
Add the SSH public key to that user's authorized_keys file
It's critical to chown the directory back to the user, or the SSH command will reject the modified file.
sudo mkdir /home/$NEWUSER/.ssh/
echo "$SSHPUBKEY" | sudo tee -a /home/$NEWUSER/.ssh/authorized_keys >/dev/null
sudo chown -R $NEWUSER:$NEWUSER /home/$NEWUSER/.ssh
Set up sudo permissions for that user
This uses the standard /etc/sudoers.d directory (found in all major distributions) to add sudo permissions with an "ALL" role to the user account.
echo "$NEWUSER ALL=(ALL) NOPASSWD: ALL" | sudo tee "/etc/sudoers.d/$NEWUSER" >/dev/null
(Disclaimer: I wrote the first release of a tool that automates this at Userify.)
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "2"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f958902%2fhow-do-i-create-a-user-and-add-an-ssh-key-on-an-ec2-instance%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Create the user account
First,. create the user account using the standard Linux/UNIX useradd
command:
NEWUSER='newusername'
SSHPUBKEY='ssh-ed25519 AAAA..xyz jamieson@desktop'
sudo useradd -m $NEWUSER
Add the SSH public key to that user's authorized_keys file
It's critical to chown the directory back to the user, or the SSH command will reject the modified file.
sudo mkdir /home/$NEWUSER/.ssh/
echo "$SSHPUBKEY" | sudo tee -a /home/$NEWUSER/.ssh/authorized_keys >/dev/null
sudo chown -R $NEWUSER:$NEWUSER /home/$NEWUSER/.ssh
Set up sudo permissions for that user
This uses the standard /etc/sudoers.d directory (found in all major distributions) to add sudo permissions with an "ALL" role to the user account.
echo "$NEWUSER ALL=(ALL) NOPASSWD: ALL" | sudo tee "/etc/sudoers.d/$NEWUSER" >/dev/null
(Disclaimer: I wrote the first release of a tool that automates this at Userify.)
add a comment |
Create the user account
First,. create the user account using the standard Linux/UNIX useradd
command:
NEWUSER='newusername'
SSHPUBKEY='ssh-ed25519 AAAA..xyz jamieson@desktop'
sudo useradd -m $NEWUSER
Add the SSH public key to that user's authorized_keys file
It's critical to chown the directory back to the user, or the SSH command will reject the modified file.
sudo mkdir /home/$NEWUSER/.ssh/
echo "$SSHPUBKEY" | sudo tee -a /home/$NEWUSER/.ssh/authorized_keys >/dev/null
sudo chown -R $NEWUSER:$NEWUSER /home/$NEWUSER/.ssh
Set up sudo permissions for that user
This uses the standard /etc/sudoers.d directory (found in all major distributions) to add sudo permissions with an "ALL" role to the user account.
echo "$NEWUSER ALL=(ALL) NOPASSWD: ALL" | sudo tee "/etc/sudoers.d/$NEWUSER" >/dev/null
(Disclaimer: I wrote the first release of a tool that automates this at Userify.)
add a comment |
Create the user account
First,. create the user account using the standard Linux/UNIX useradd
command:
NEWUSER='newusername'
SSHPUBKEY='ssh-ed25519 AAAA..xyz jamieson@desktop'
sudo useradd -m $NEWUSER
Add the SSH public key to that user's authorized_keys file
It's critical to chown the directory back to the user, or the SSH command will reject the modified file.
sudo mkdir /home/$NEWUSER/.ssh/
echo "$SSHPUBKEY" | sudo tee -a /home/$NEWUSER/.ssh/authorized_keys >/dev/null
sudo chown -R $NEWUSER:$NEWUSER /home/$NEWUSER/.ssh
Set up sudo permissions for that user
This uses the standard /etc/sudoers.d directory (found in all major distributions) to add sudo permissions with an "ALL" role to the user account.
echo "$NEWUSER ALL=(ALL) NOPASSWD: ALL" | sudo tee "/etc/sudoers.d/$NEWUSER" >/dev/null
(Disclaimer: I wrote the first release of a tool that automates this at Userify.)
Create the user account
First,. create the user account using the standard Linux/UNIX useradd
command:
NEWUSER='newusername'
SSHPUBKEY='ssh-ed25519 AAAA..xyz jamieson@desktop'
sudo useradd -m $NEWUSER
Add the SSH public key to that user's authorized_keys file
It's critical to chown the directory back to the user, or the SSH command will reject the modified file.
sudo mkdir /home/$NEWUSER/.ssh/
echo "$SSHPUBKEY" | sudo tee -a /home/$NEWUSER/.ssh/authorized_keys >/dev/null
sudo chown -R $NEWUSER:$NEWUSER /home/$NEWUSER/.ssh
Set up sudo permissions for that user
This uses the standard /etc/sudoers.d directory (found in all major distributions) to add sudo permissions with an "ALL" role to the user account.
echo "$NEWUSER ALL=(ALL) NOPASSWD: ALL" | sudo tee "/etc/sudoers.d/$NEWUSER" >/dev/null
(Disclaimer: I wrote the first release of a tool that automates this at Userify.)
answered 3 mins ago
Jamieson BeckerJamieson Becker
770712
770712
add a comment |
add a comment |
Thanks for contributing an answer to Server Fault!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f958902%2fhow-do-i-create-a-user-and-add-an-ssh-key-on-an-ec2-instance%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown