I'm trying to set up an ssh connection from ServerA to ServerB without password, and the ssh connection keeps asking me for the passphrase of my private key.
Here is my configuration:
ServerA
The /home/user/.ssh folder has a CHMOD: rwx------, and is owned by user:user
The files /home/user/.ssh/id_rsa.pub and /home/user/.ssh/id_rsa have a CHMOD: -rw------- and are owend by user:user
ServerB
I created a user serverA on the ServerB.
The folder /home/serverA/.ssh has a CHMOD: drwx------ and is owned by serverA:serverA
The file /home/serverA/.ssh/authorized_keys contains the public key of the user on the ServerA, and has a CHMOD: -rw-r-----
In the file /etc/ssh/sshd_config I added the following lines:
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
However, when I am on ServerA and I try to type:
ssh ServerA#ServerB, it asks me for the passphrase of my private key. When I give it, I get connected.
Do you know how I could do to avoid typing the passphrase of ServerA every time?
When you run ssh-keygen, you must have given the certificate a pass phrase. To not have to enter a pass phrase just press enter on that question to set an empty one when.
You can use ssh-agent, which will "remember" your passphrase for specified time. In short:
eval `ssh-agent` # start ssh-agent
ssh-add /path/to/your.key # remeber the key
ssh ServerA#ServerB # will not ask for a passphrase
for more information, check more questions about ssh-agent or its manual page.
Related
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've got the following question, I've installed a server with CentOS 7. Now I want to use this server for git.
The problem is I can't make an SSH connection to the sever to do this. I already made keys and I putted the id_rsa key in C:\Users\MYNAME.ssh
I also created an git user on the server and putted the public key in /home/git/.ssh/authorized_keys
When I want to clone the repository to my server I use the following command:
$ git clone ssh://git#IP/domains/optiekruymen.be/public_html/.git
The output is
Cloning into 'public_html'...
Enter passphrase for key '/c/Users/MYNAME/.ssh/id_rsa':
git#IP's password:
I don't understand why I still need to give the git password, beceause I want tot use the ssh connection and not the password of the git user.
I generated the key on Centos using ssh-keygen, than i copied using
cat id_rsa.pub >> /home/git/.ssh/authorized_keys
to copy the file to the git user user next i downloaded the key to my pc and copied id_rsa to /c/Users/MYNAME/.ssh/id_rsa
Extra output
.ssh file settings
drwx------ 2 git git 4096 Feb 13 20:59 .ssh
authorized_keys file settings
-rw-r--r-- 1 git git 408 Feb 13 20:53 authorized_keys
other debug info
debug1: Trying private key: /c/Users/USERNAME/.ssh/id_rsa
debug3: sign_and_send_pubkey: RSA
SHA256:xUB8U9Mn3EkwzhLXjsBlZU1tJMViEfM/Yit5Kjkv/TA
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with mic,password
This message means that your private key is password-protected (encrypted with a password), before a connection to the remote host can be made, this key needs to be decrypted (by you inputing the password).
The easiest way to solve thi is to remove the passphrase from the private key.
From this message:
git#IP's password:
You can see that you are being for the password for the git user.
As you mentioned above once you added the user to the /etc/ssh/sshd_config its no longer asking you for password.
/etc/ssh/sshd_config file
The /etc/ssh/sshd_config file is the system-wide configuration file for OpenSSH which allows you to set options that modify the operation of the daemon.
This file contains keyword-value pairs, one per line, with keywords being case insensitive.
I solved this by adding the user git to the /etc/ssh/sshd_config file
and checking the following configurations
Home directory on the server should not be writable by others: chmod go-w /home/user
SSH folder on the server needs 700 permissions: chmod 700 /home/user/.ssh
Authorized_keys file needs 644 permissions: chmod 644 /home/user/.ssh/authorized_keys
Make sure that user owns the files/folders and not root: chown user:user authorized_keys and chown user:user /home/user/.ssh
Put the generated public key (from ssh-keygen) in the user's authorized_keys file on the server
Make sure that user's home directory is set to what you expect it to be and that it contains the correct .ssh folder that you've been modifying. If not, use usermod -d /home/user user to fix the issue
Finally, restart ssh: service ssh restart
Then make sure client has the public key and private key files in the local user's .ssh folder and login: ssh user#host.com
I am new to Ubuntu-Linux,i have to create a ssh user in remote system and generate its key. and access this system by key_file through the command.
ssh -i key_file user#host
Can any body tell me how can i do ?
On the system you are trying to connect to, the public key (usually id_rsa.pub or something similar) needs to be added to the authorized_keys file.
If the user is brand new and the authorized_keys file doesn't exist yet, this command will create it for you.
cp ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys
Next just make sure sshd is running on the host and you should be able to connect with the command you posted.
on remote-server-
ssh-keygen
ssh-copy-id user#host
cd .ssh
make a copy of the file id_rsa and give any body who want to access this server/system.
on the other system
ssh -i id_rsa user#host
If you want to connect to another host as user "user", what you need is the public key of the user that is going to open that connection, i.e. the user you are logged in on your desktop computer or some server you are coming from, not for the user, you are logging in to on the remote host.
You can check, if the keys for your current user are already created in $HOME/.ssh; there you should find something like "id_rsa" and "id_rsa.pub" (for rsa keys). If they don't exist, you create them by calling
ssh-keygen -t rsa
The public key that is generated that way, id_rsa.pub in this example, has to be put in a file ${HOME of user on remote host}/.ssh/authorized_keys on the target host.
If this file does not exist on the remote host or if even .ssh does not exist, you have to create those files with the following permissions:
.ssh 700
.ssh/authorized_keys 600
See http://www.openssh.com/faq.html#3.14 for details.
A detailed description of the process can be found here:
https://help.github.com/articles/generating-ssh-keys/
I have two server
server1
server2
want to login server 2 from server 1,I added both pub key (ssh_host_rsa_key.pub) in one another server in .ssh/authorized_keys.
when i run #cd /etc/ssh;ls -ltr able to see below file
sshd_config
ssh_config
moduli
ssh_host_key.pub
ssh_host_key
ssh_host_rsa_key.pub
ssh_host_rsa_key
ssh_host_dsa_key.pub
ssh_host_dsa_key
Host keys ssh_host_rsa_key.pub are stored automatically by ssh in known_hosts files; they are not intended to be managed by the user.
The authorized_keys is intended for user identity files. What you really want to do is to use ssh-keygen to generate an identity file representing you:
ssh-keygen -t ecdsa
Two identity files are generated: the private key id_ecdsa and the public key id_ecdsa.pub. Copy the public key into server2's .ssh/authorized_keys.
If you created a passphrase for your identity files, that's what you will be using from now on. Otherwise, your login will be password-less.
I was referring to http://www.mtu.net/~engstrom/ssh-agent.php
My public key is listed under ~/.ssh/authorized_keys at remote1. During SSH login connect,
it's working fine(loaded my private key under connection-Auth), it asked for passphrase which I provided then login is successful.
But when switching between servers like from remote2, do SSH remote1, it would ask for a password. Trying to set up SSH agent forwarding according to that site but was to no avail...ssh-add never prompts me for private-key-passphrase or was it wrong what i was doing trying to follow the process described?
I basically did
$ eval ssh-agent
$ ssh-add (some do ssh-add ~/.ssh/id_rsa--> wonder wat id_rsa is referring to as I only have the auth_keys file under .ssh)
Saw some resources described to do chmod 600 ~/.ssh/authorized_keys, but not sure if that's applicable to my case.
ssh-agent wrap another command, you can for example wrap a shell
ssh-agent bash
Then, in that shell, you need to add your private key, and type your passphrase :
ssh-add /path/to/your/private/key # (by default : ~/.ssh/id_rsa)
Then, when you use ssh to connect, add the -A option :
ssh -A user#remote1
That's it, your key is forwarded, you can see it if you type (on remote1) :
ssh-add -L
You can now connect to your remote2, using that private key.
Be careful when you use ssh forwarding. Anyone with root access on remote1 could use your identity to connect on remote2 while you are connected.
I am pretty sure that ~/.ssh/authorized_keys must always be chmod 600. This is a sensitive file that must be protected.