2

I am a casual linux user but I am having a some difficulty understanding some directions sent to me from a company we provide data to. They want us to use ssh (which I have used before) to transfer data with the scp. The problem is that I have never used ssh-keygen nor do I completely comprehend how it works. Could someone help me along. I will include the instructions so you can see exactly what they sent me.

*In the ‘home’ directory of the account that will be sending the data, it is best to create a ‘.ssh’ directory (if it does not exist). This is the default location that is used for managing all ssh keypairs. You can have several different keypairs, and so naming conventions are helpful (as a default, ssh-keygen uses ‘id-rsa’ for the filename of the keys (id-rsa for the private key and id-rsa.pub for the public key). The command that I usually recommend to create the key pair would be; ssh-keygen -t rsa -N "" -f name -C "account@server_name - brief description"

Where; the ‘-t’ flag is for the type of key to create (rsa), the ‘-N’ flag is for optional passphrase (“” is a null string – essentially no passphrase set (which is what you want for an automated process, but not what you want when/if setting up for personal use)), the ‘-f’ flag is for filename (this is what would be used to replace the default ‘id_rsa’ name – this can then be specified when invoking the ‘scp’ command), the ‘-C’ flag is for a comment field (this is useful if you have multiple keys, you can insert a brief description on what the key is used for – I typically recommend that the server and account that generated the key is included with a brief description on its primary use; ‘unduser1@hostname – transfer data to X company).*

Thanks for the help!

3
  • What operating system are you doing this from (also Linux, or Windows, or MacOS, etc.?). Can you logon to the new linux machine via password already?
    – Nicholaz
    Jun 3, 2013 at 13:28
  • I am using linux on my computer but the machine that will most likely be doing the data transfer is a windows machine. The server that I am transferring data to I don't have "access" to. Thats what I thought generating keys was supposed to help me with. From what I know I feel like they need to provide me with a password to ssh but since I dont know enough about what keygen does I am not sure if my thinking is correct. I thought keygen was used to create keys for a server I manage not one they manage. Jun 3, 2013 at 13:37
  • Ok in that case, let me edit my answer a bit.
    – Nicholaz
    Jun 3, 2013 at 13:43

1 Answer 1

3

Essentially what you need to do is to create a public/private key pair, using keygen. This will give you a pair of files e.g. id_rsa and id_rsa.pub.

With SSH you can put the pub part into a remote account and when logging in, ssh can check that against the non public part and let in everybody who has it. Very loosely of think of id_rsa.pub as the lock and id_rsa as the key.

So on any Linux oder Unix or MacOS machine run the keygen that will give you those two files:

ssh-keygen -t rsa -N "" -C "my rsa key"

Then send the id_rsa.pub file to the admins maintaining the remote machine (and they need to place it in the ~/.ssh folder on the remote machine then). If you have a password for the remote machine, you can use ssh-copy-id user@hostname (man page) yourself to send your key pair there.

Keep the private file (id_rsa) for yourself. It then needs to go to the machine from where you initiate the connection. That depends a lot on what operating system and SSH client software you use.

If that is a Linux too, you put it into the ~/.ssh folder there (create one if necessary).

  mkdir ~/.ssh
  chmod 700 ~/.ssh
  mv id_rsa ~/.ssh
  chmod 700 ~/.ssh/id_rsa

From then you should be able to ssh to the remove machine as

 ssh [email protected] 

or

 ssh -i ~/.ssh/id_rsa [email protected] 

On Windows it would depend on the terminal software you use for SSH, e.g. with the ZOC SSH/Telnet Terminal you can provide the filename for the private file with the login information (see this screenshot, the file would go into the "ssh key file" field). This varies with the software.

8
  • So if i generate keys for my specific machine I will need to provide the the id_rsa.pub key to the owner of the other server in order to connect to it. Is that correct? Jun 3, 2013 at 13:43
  • Yes. You create a pair. And the .pub file needs to go to the server you log into (think of it as the lock), if you can't login there, the admins need to put it into your account. And the other file remains with you on the server which initiates the connections (from where you make the ssh/scp call).
    – Nicholaz
    Jun 3, 2013 at 13:49
  • Awesome! Thats kind of what I thought but wasn't quite sure. I think it would be easier preforming the upload from a linux box but everyone computer here is Windows besides mine. Thanks for the help! Jun 3, 2013 at 14:05
  • Glad to hear. Please consider to check the answer as correct then.
    – Nicholaz
    Jun 3, 2013 at 14:17
  • Remember that if you've generated your keys on a linux machine, and have the password for the remote server, you can also run ssh-copy-id to automate the copy process :)
    – NickW
    Jun 3, 2013 at 15:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .