SSH key generation using ssh-keygen / OpenSSL - linux

we have 2 different servers to achieve connectivity, currently we are using password based login, need to disable this password based login & need to use only key based login, where key needs to be generated using ssh-keygen or openssl ? so that i can login like below
ssh -i .ssh/mykey.pem user#host
above command shouldn't prompt for password
i have tried generating using ssh-keygen followed with ssh-copy-id but these are prompting for password every time & also we don't want to setup passwordless connection.

To generate new RSA pair you can use command
ssh-keygen -t rsa
Then in sshd server config you have to setup
PasswordAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
And to your latest question: Did you setup RSA key passphrase during pair generation? If yes user will be asked to enter this password instead of system user password.

Related

Change Azure VM authentication to ssh key

I have Linux VM on Azure which at first set without SSH keys. which means authentication is made only with password via SSH. I would like to change it now. I tried the way I know, I can login with the keys - but still login with password.
What else did I miss? There is something else?
Thanks
Tried to configure SSH key, disable the 'passwordauthentication'
Change ssh config
Add key via azure portal
Try to following these steps -
Login to your existing azure VM using passwords authentication.
Create new ssh key pair.
ssh-keygen -t rsa -b 2048
Replace ~/.ssh/authorized_keys with ~/.ssh/id_rsa.pub key
mv ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys
Save ~/.ssh/id_rsa public key to your local system.
Edit /etc/ssh/sshd_config and make following changes
Change PasswordAuthentication to this:
PasswordAuthentication no
Change PubkeyAuthentication to this:
PubkeyAuthentication yes
Change PermitRootLogin to this:
PermitRootLogin no
Change ChallengeResponseAuthentication to this:
ChallengeResponseAuthentication no
Restart the vm using following command
sudo systemctl restart ssh
I tried to reproduce the same in my environment and got the results like below:
I have created Linux VM on Azure first set without SSH keys only with password via SSH then I tried to authentication to ssh key like below:
Create SSH key pair:
ssh-keygen -t rsa -b 2048
Then, use /home/<user>/.ssh/id_rsa.pub
Enter passphrase: Give your password
Once you enter password RSA will executed successfully like below:
Then try to move to id_rsa to authorized using below script:
`mv/home/<user>/.ssh/id_rsa.pub/home/<user>/.ssh/authorized_keys`
when I run this cmd cat id_rsa I got public key successfully like below
I agree with schine som And save public key open config file with vi and try restart like below:
PasswordAuthentication no
PubkeyAuthentication yes
PermitRootLogin no
ChallengeResponseAuthentication no

In Azure, how to change the authentication of the server?

When spinning up a linux virtual machine, I have chosen the authentication type as password. Now I want to change to ssh. How to achieve this?
Thanks
You can use Azure portal to reset password, like this:
If you want to change authentication type, you can follow this steps:
1. Create an SSH key pair
ssh-keygen -t rsa -b 2048
2. rename id_rsa.put to authorized_keys
mv /home/user/.ssh/id_rsa.pub /home/user/.ssh/authorized_keys
3.Copy id_rsa to your local, then you can use this key to SSH it.

openWRT Dropbear SSH key authentication fails with "unknown algo"

Good day, I'm trying to figure out how to get a user to ssh into openWRT with only a key.
I followed these instructions:
https://wiki.openwrt.org/oldwiki/dropbearpublickeyauthenticationhowto.
In short:
On a Linux box:
If you haven't already got a
.ssh/id_dsa.pub
ssh-keygen -t dsa
scp ~/.ssh/id_dsa.pub root#192.168.1.1:/tmp
On openWRT:
cd /etc/dropbear
cat /tmp/id_*.pub >> authorized_keys
chmod 0600 authorized_keys
When I try and ssh in, I get this error:
authpriv.warn dropbear[2085]: Pubkey auth attempt with unknown algo for 'MyUser' from 1.2.3.4:11111
I have tried generating a RSA key too, same result.
I can log in as the user using a password:
authpriv.notice dropbear[2089]: Password auth succeeded for 'MyUser' from 1.2.3.4:11111
Maybe it's the problem of the OpenWRT version.
Try ${HOME}/.ssh/authorized_keys instead.

need to make password less login for same linux server with same user

i need to make passwordless login for same linux server with same user.
[airwide#eir ~]$ hostname -i
10.3.7.73
[airwide#eir ~]$ ssh airwide#10.3.7.73
airwide#10.3.7.73's password:
how can make to passwordless for same server?
Password-free login via SSH is managed using SSH keys. You can generate a keypair using the command ssh-keygen. The ssh keypair is usually stored in ~/.ssh in a pair of files named id_rsa and id_rsa.pub. When you use SSH to connect to a server, the SSH command will look for a private key in ~/.ssh/id_rsa, and will attempt to authenticate using that key. In order to authorize the key, you will need to place the public key into your authorized_keys file:
`cat ~/./ssh/id_rsa.pub >> ~/.ssh/authorized_keys`
Once you've done that, you will be able to use SSH to connect without a password from the server where the id_rsa file is to the server that has the content of id_rsa.pub in its authorized_keys file. (You can do this for same-server, as in your question, or between multiple servers. Either way, it's the same process.)
Add server's private key in known host key under .ssh folder.
You are looking for ssh keys. You can create one by entering ssh-keygen. This wil create a public key and a private key. You place the public key on the remote server, and then you can use SSH without a password.
More details, and howto:
https://wiki.archlinux.org/index.php/SSH_keys

ssh-keygen - how to set an rsa key with a certain username

I just installed ubuntu and would like to set its rsa keys up with bitbucket/github. When I ssh-keygen the keys are generated as they should be
ssh-rsa AA...yBEz3pLL georgemauer#ubuntu
which is perfectly usable except the username part. In every rsa key I've generated previously, the username section read my email address:
ssh-rsa AA...yBEz3pLL gmylastname#gmail.com
No, it's not a major impediment but if I don't get this right it will drive me crazy. How, do I generate with rsa keys with an email username of my choice?
Use the -C option to provide a new comment with your key.
Explanation: In general, the last string in your ssh public key would be a single comment which in default configured to your user#host. You can override this comment by adding -C argument and edit this string.
For example In default behaviour, lets say that - if your linux hostname is Ubuntu and your user name is john.doe while you watch your public key performing cat ~/.ssh/id_rsa.pub you would see something like this:
ssh-rsa <someReallyBigToken>== john.doe#ubuntu
Documentation:
ssh-keygen will by default write keys in an OpenSSH-specific format.
This format is preferred as it offers better protection for keys at
rest as well as allowing storage of key
comments within the private key file itself. The key comment may be useful to help identify the key. The comment is initialized to
``user#host'' when the key is created, but
can be changed using the -c option.
Solution: override this comment and use -C argument for comment.
ssh-keygen -t rsa -b 4096 -C message-in-a-bottle
cat ~/.ssh/id_rsa.pub
// output:
ssh-rsa <someReallyBigToken>== message-in-a-bottle
ssh-keygen -t rsa -f ~/.ssh/[KEY_FILENAME] -C [USERNAME]
I use this command for generating the SSH key for generating GitHub, GitLab, and GCP.
Here is the documentation for creating an SSH key with a username.

Resources