I am trying to connect to a remote server without a password and i followed the instructions on this link exactly (http://kb.mediatemple.net/questions/1626/Using+SSH+keys+on+your+server) , I also checked the sshd_config file
SAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile %h/.ssh/authorized_keys
However i still get password prompt when i try to log in.
Any help ?
Check for your ~/.ssh directory and/or id_rsa/id_dsa file permissions.
Your ~/.ssh directory should be 700 and your private key files should be 600.
The security log on your system (e.g. /var/log/secure) will often help you in determining what it objects to in using your keys. Please check that log for some clues.
This is simple problem due to ~/.ssh/authorized_keys file permission. By default the mode will be set to 664 when you create the file manually. Change the mode to 600 and you can login without password
sudo chmod 700 ~/.ssh
sudo chmod 600 ~/.ssh/authorized_keys
Now try ssh into the server
Related
I want to create an own git server. I started with a root user and here is the following I did:
mkdir /srv/git/project.git
useradd -r -d /srv/git git
passwd git
Now I have a new user git (can log in via su git from my root account).
I want to login via git#mywebsite.com without the use of a password. Right now, it will ask for a password every time.
For root, I have my SSH public key in .ssh/authorized_keys. The key should also work for git. Do I have to add another authorized_keys file for this git user? With my useradd command, I do not create a home directory where I could add it, so where should it go?
Thank you all for your help!
Run sudo tail -f /var/log/auth.log and attempt to login once more from a different console. You will see now the lag that should tell you why exactly the login was denied.
In my case there were wrong permissions for the home folder.
You did create a home directory, it just isn't sitting under /home.
/srv/git
Under that directory create a .ssh directory, fix the permissions:
mkdir /srv/git/.ssh
chmod 0700 /srv/git/.ssh
Create a new authorized_keys file with the public key in it, fix the permissions:
vim /srv/git/.ssh/authorized_keys # or method of your choice
chmod 0600 /srv/git/.ssh/authorized_keys
When I issue ssh -v hostname, it tells me successful. But permission denied(publickey) when issuing ssh -v user#hostname. What's the differences between them? And I try to solve this problem by some ways, but weren't effective. Such as:
chmod 700 ~/.ssh/
chmod 600 ~/.ssh/authorized_keys
Restorecon ~/.ssh/authorized_keys
I guess the problem is about context, because after issuing ssh -v hostname, the debug information tells me unable to get valid context. And issuing ssh[user#]hostname it authorized id_rsa, id_ecdsa, and id_ed25519 and skiping id_dsa (probably the config setting).
When user isn't specified, the .ssh config is searched for a default one for the given host, and if there's none, the same username as on the source machine is used.
To get more information, add copy&paste of the .ssh/config and outputs of both the ssh commands.
When using ssh user#hostname you explcitely try to log in as user on hostname. The login failes because you need to create an authorized_keys file in this user's home, too, as you did for the default user which is used when user is not given. Obviously authentication by password is disabled, else ssh would ask for it.
On my Windows 10, I am running into the problem of not being able to connect to m Vagrant virtual machine via ssh user with public key authentication method at git bash using command such as
$ ssh -v lauser#127.0.0.1 -p 2222 -i ~/.ssh/id_rsa
I would be prompted for password, as if the public key I copied to in the ~/.ssh/Authorized_keys file inside the vm were not seen. Meanwhile,the password authentication method works, as well as 'vagrant ssh'.
I have made sure to
create key pairs locally, create a .ssh directory at the remote, and add pub key string to the remote's .ssh /authorized_keys file; both the .ssh and the .ssh /authorized_keys file are owned by the user(lauser), and set at 700 and 644
edit the /etc/ssh/sshd_config file on vm to use
RSAAuthentication yes
PubkeyAuthentication yes
and restarted the sshd server (with 'sudo service ssh restart').
verify that firewall has been disabled temporarily to eliminate any complication.
verify that there is only one vm running, all others are either in 'suspend' or 'halt' mode.
confirm the file type by 'file ~/.ssh/authorized_keys', and get confirmation '~/.ssh/authorized_keys: OpenSSH RSA public key'
verify that the keys match by comparing the output from 'sudo cat ~/.ssh/authorized_keys' in vm and the output from ' cat ~/.ssh/id_rsa.pub' at the local.
but still I get Permission denied (publickey) when trying to connect through public key authentication.
It sounds like you've done everything correctly so far. When I run in to this problem, it's usually due to directory permissions on the target user's home directory (~), ~/.ssh or ~/.ssh/authorized_keys.
See this answer on SuperUser.
I faced same challenges when the home directory on the remote did not have correct privileges. Changing permissions from 777 to 744 helped me
I have an id_rsa and id_rsa.pub on my computer also tied into my BitBucket account.
As I understand I can use this public key anywhere I please (as long as my private matches).
The Problem: I cannot figure out how to get any server to accept the public key, do you see what I've done wrong?
$ cat id_rsa.pub >> authorized_keys
$ service ssh restart (I suppose this isn't needed)
$ git pull origin master
$ Permission denied(publickey)
What am I doing wrong? I've been stuck for days.
If you copied your root's authorized_keys you may have to do more than you are used to:
chmod 700 .ssh
sudo chmod 640 .ssh/authorized_keys
sudo chown $USER .ssh
sudo chown $USER .ssh/authorized_keys
Where $USER is your linux username.
Make sure the permissions on ~/.ssh are 700 i.e. only accessible by the owner, and the permissions on the public and private key files are not writable except by the owner.
Make sure the key files are in ~/.ssh !
Make sure the key is being used (try ssh'ing to the right user # the bitbucket server using ssh -v)
You need to copy the content of id_rsa.pub to the bitbucket avcount its in the settings page
For more info https://confluence.atlassian.com/display/BITBUCKET/How+to+install+a+public+key+on+your+Bitbucket+account
I connected 3 data nodes(in all these data nodes pass-wordless is working fine) in my cluster which are working fine but when i try to connect another data node pass-wordless ssh not working in fourth data node.
IP address of first three data nodes:
172.20.93.192(name node)
172.20.94.189(data node)
172.20.94.145(data node)
172.20.94.193(data node)
now my fourth data node's IP address is 172.20.95.6 where password-less is not working.
I am generating keys with
ssh-keygen -t rsa
I am doing the same process for the fourth data node as above three data nodes but it is not working. Why? what may be the reason?
I had a very similar problem today with CentOS servers. The problem turned out that the /root folder had wrong permissions. In fact, the /var/log/secure log file showed this error:
Sep 3 09:10:40 nec05 sshd[21858]: Authentication refused: bad ownership or modes for directory /root
This is what it wrongly was:
[root#nec05 ~]# ls -ld /root
drwxrwxrwx. 32 root root 4096 Sep 3 09:54 /root
Using chmod fixed it:
[root#nec05 ~]# chmod 550 /root
[root#nec05 ~]# ls -ld /root
dr-xr-x---. 32 root root 4096 Sep 3 09:54 /root
After that, passwordless login worked on this particular server.
More information would be required to get the "real" cause. However here it goes two of the most common problems I have found and not related to the key configuration itself (taking into account that you use Linux :)):
SSHD in the remote machine is configured in restricted mode for "root" and you are trying to ssh as root. SOLUTION: Copy /etc/ssh/sshd.conf from one of the working machines to the faulty and restart ssh server.
Home folder of the user used for remote login has invalid permissions. Many default configurations for SSH Daemons contain restrictions about the permissions of the user home folder for security purposes. SOLUTION: Compare with working nodes and fix. (Sometimes you would see a warning/error log in /var/log/messages.
If you follow the process to integrate the keys from the scratch and review the permissions for all the files involved you should face no issues.
Please answer back with sshd.conf file as well as the logs from a remote login with -v (ssh -v IPADDR) for a better analysis.
I went through the same errors recently. All my file permissions are set up correctly but still ssh asks for password. Finally I figured out it is due to one missing at /etc/ssh/sshd_config: you shoud add "AuthorizedKeysFile %h/.ssh/authorized_keys", so that sshd will look for the publickey file at your home dir.
After doing this the problem is gone.
You would have to more elaborate your problem i.e. whether you are using the same private-public key pair for all servers.
Secondly you must try ssh with -v flag it will give you some hint like which private key it is using for authentication, what is the cause of authentication failure.
Thirdly Verify the permission of .ssh/authorized_keys at server end. It should not have write permission to group or other users.
You can simply use
ssh-keygen -f # to generate ssh key pair.
ssh-copy-id # #to copy public key in the server's authorized key.
troubleshoot checklist:
example: Machine A passwordless login to B
turn off selinux on B
FOR BOTH A&B: make sure correct permission for .ssh(700) and .ssh/authorized_keys (600)
check on B: /etc/ssh/sshd_config: PubkeyAuthentication yes
check firewall on B
check the log /var/log/secure
if you've renamed id_rsa/id_rsa.pub to example id_rsa_b/id_rsa_b.pub, you should do ssh -i .ssh/id_rsa_b user#MachineB
refer
I am going to explain with example:
Suppose there are two server server1(192.168.43.21) and server2(192.168.43.33).If you want password less ssh between server1 and server2 where user is admin then follow below steps-
To install run command: yum install openssh-server openssh-clients
To create ssh key run command : ssh-keygen -t rsa on server1 and server2
SELINUX disable at : vim /etc/selinux/conifg
SELIINUX=disabled
After changing SELINUX need to reboot.
Add user to AllowUsers ,AllowGroups and PermitEmptyPasswords on at :
vim /etc/ssh/sshd_config
AllowUsers admin
AllowGroups admin
After update restart sshd: systemctl restart sshd
Go to home directory of admin user : cd ~
Go to ssh folder : cd .ssh and copy id_rsa.pub key from server1 and paste it into server server2 authorized.key file of .ssh folder.
note: Instead of manually copy we can use:
From server2 use command: `ssh-copy-id admin#serve1`
From server1 use command: `ssh-copy-id admin#server2`
Now try ssh from server1 to server2 and server2 to server1
From server1 command: `ssh admin#server2`
From server2 command: `ssh admin#server1`
If not working then check firewall user use command:
To check status of firewall run command: firewall-cmd --state
If it is running then check ssh port is added or not using below command:
firewall-cmd --list-all
If port is not added then need need to add to desired zone.
If firewall is not mandatory to active in that cat you can stop firewall and
mask it using below command:
systemctl stop firewalld
systemctl disable firewalld
systemctl mask --now firewalld
Please check if selinux is disabled.
In my case, worked after selinux disabled.
Method in linux is to generate encrypted key (either with rsa or dsa ) for that user , save that key in authorized key , assign rights to that folder and file in it.
1: Generate key with command
ssh-keygen –t dsa –P '' –f ~/.ssh/id_dsa
Your public key has been saved in /home/username_of_pc/.ssh/id_dsa.pub
2:Add that key in authorized key.
Cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
Set permissions for folder where it’s saved.
if you need it on another server then simply copy it to other machine.
3:Check ssh by simply typing
ssh localhost
It should not ask for password and only display last login time , then it’s setup correctly. Remember not to use root for ssh.