How to ssh to remote server using a private key?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
59
down vote

favorite
17












I have two servers. Both servers are in CentOS 5.6. I want to SSH from Server 1 to Server 2 using a private key I have (OpenSSH SSH-2 Private Key).



I don't know how to do it over unix. But what I did on windows using Putty was to feed my OpenSSH private key to putty-gen and generate a private key in PPK format.



However, I would be creating a bash script from server 1 that will execute some commands on server 2 via SSH.



How do I SSH to Server 2 using my private key file from Server 1?










share|improve this question





















  • On many Linux and Unix systems, this can be done using ssh-copy-id user@machine
    – Paul Tomblin
    Oct 25 '11 at 20:22














up vote
59
down vote

favorite
17












I have two servers. Both servers are in CentOS 5.6. I want to SSH from Server 1 to Server 2 using a private key I have (OpenSSH SSH-2 Private Key).



I don't know how to do it over unix. But what I did on windows using Putty was to feed my OpenSSH private key to putty-gen and generate a private key in PPK format.



However, I would be creating a bash script from server 1 that will execute some commands on server 2 via SSH.



How do I SSH to Server 2 using my private key file from Server 1?










share|improve this question





















  • On many Linux and Unix systems, this can be done using ssh-copy-id user@machine
    – Paul Tomblin
    Oct 25 '11 at 20:22












up vote
59
down vote

favorite
17









up vote
59
down vote

favorite
17






17





I have two servers. Both servers are in CentOS 5.6. I want to SSH from Server 1 to Server 2 using a private key I have (OpenSSH SSH-2 Private Key).



I don't know how to do it over unix. But what I did on windows using Putty was to feed my OpenSSH private key to putty-gen and generate a private key in PPK format.



However, I would be creating a bash script from server 1 that will execute some commands on server 2 via SSH.



How do I SSH to Server 2 using my private key file from Server 1?










share|improve this question













I have two servers. Both servers are in CentOS 5.6. I want to SSH from Server 1 to Server 2 using a private key I have (OpenSSH SSH-2 Private Key).



I don't know how to do it over unix. But what I did on windows using Putty was to feed my OpenSSH private key to putty-gen and generate a private key in PPK format.



However, I would be creating a bash script from server 1 that will execute some commands on server 2 via SSH.



How do I SSH to Server 2 using my private key file from Server 1?







ssh openssh






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Oct 25 '11 at 19:24









Aivan Monceller

4801510




4801510











  • On many Linux and Unix systems, this can be done using ssh-copy-id user@machine
    – Paul Tomblin
    Oct 25 '11 at 20:22
















  • On many Linux and Unix systems, this can be done using ssh-copy-id user@machine
    – Paul Tomblin
    Oct 25 '11 at 20:22















On many Linux and Unix systems, this can be done using ssh-copy-id user@machine
– Paul Tomblin
Oct 25 '11 at 20:22




On many Linux and Unix systems, this can be done using ssh-copy-id user@machine
– Paul Tomblin
Oct 25 '11 at 20:22










5 Answers
5






active

oldest

votes

















up vote
51
down vote



accepted










You need your SSH public key and you will need your ssh private key. Keys can be generated with ssh_keygen.
The private key must be kept on Server 1 and the public key must be stored on Server 2.



This is completly described in the manpage of openssh, so I will quote a lot of it. You should read the section 'Authentication'. Also the openSSH manual should be really helpful: http://www.openssh.org/manual.html



Please be careful with ssh because this affects the security of your server.



From man ssh:



 ~/.ssh/identity
~/.ssh/id_dsa
~/.ssh/id_rsa
Contains the private key for authentication. These files contain
sensitive data and should be readable by the user but not acces-
sible by others (read/write/execute). ssh will simply ignore a
private key file if it is accessible by others. It is possible
to specify a passphrase when generating the key which will be
used to encrypt the sensitive part of this file using 3DES.

~/.ssh/identity.pub
~/.ssh/id_dsa.pub
~/.ssh/id_rsa.pub
Contains the public key for authentication. These files are not
sensitive and can (but need not) be readable by anyone.


This means you can store your private key in your home directory in .ssh. Another possibility is to tell ssh via the -i parameter switch to use a special identity file.
Also from man ssh:



 -i identity_file
Selects a file from which the identity (private key) for RSA or
DSA authentication is read. The default is ~/.ssh/identity for
protocol version 1, and ~/.ssh/id_rsa and ~/.ssh/id_dsa for pro-
tocol version 2. Identity files may also be specified on a per-
host basis in the configuration file. It is possible to have
multiple -i options (and multiple identities specified in config-
uration files).


This is for the private key. Now you need to introduce your public key on Server 2. Again a quote from man ssh:



 ~/.ssh/authorized_keys
Lists the public keys (RSA/DSA) that can be used for logging in
as this user. The format of this file is described in the
sshd(8) manual page. This file is not highly sensitive, but the
recommended permissions are read/write for the user, and not
accessible by others.


The easiest way to achive that is to copy the file to Server 2 and append it to the authorized_keys file:



scp -p your_pub_key.pub user@host:
ssh user@host
host$ cat id_dsa.pub >> ~/.ssh/authorized_keys


Authorisation via public key must be allowed for the ssh daemon, see man ssh_config. Usually this can be done by adding the following statement to the config file:



PubkeyAuthentication yes





share|improve this answer


















  • 6




    Hi thank you for the effort but I only need this. ssh -i keyfile thanks!
    – Aivan Monceller
    Oct 25 '11 at 20:59






  • 3




    After generating the key, the easiest and recommended way to install it on the server is with ssh-copy-id: ssh-copy-id -i ~/.ssh/foo.id_rsa remote.example.com.
    – Gilles
    Oct 26 '11 at 7:09






  • 2




    It's interesting how everyone forgets to mention that u need to run ssh-add after creating a key on the computer you are connecting from. that is what causes a headache to most people.
    – Luka
    Sep 19 '17 at 21:49










  • IMPORTANT NOTE: The client can have many private keys and select based on an arbitrary name in their private ~/.ssh/config file where Host= gives the arbitrary name, HostName gives either a name or IP address, Port= the target port, User is destination username, and ItentityFile= points to the private key file. This feature set is often overlooked and is THE solution to many configuration issues, such as having multiple key-pairs that otherwise collide in name-space.
    – Richard T
    Aug 25 at 22:46

















up vote
13
down vote













I used ssh with -i option to add your key here.



If you want to pass arg1,arg2 with .sh file, just pass it after .sh file and use a use space to separate it.



ssh -i home/avr/new.pem ar@231.221.54.8 "/var/www/beta/betatolive.sh mmin 30"






share|improve this answer






















  • Don't forget to set the right permissions: chmod 600 home/avr/new.pem
    – Brian Haak
    Jun 22 '17 at 3:34


















up vote
12
down vote













The first thing you’ll need to do is make sure you’ve run the keygen command to generate the keys:



ssh-keygen -t rsa


Then use this command to push the key to the remote server, modifying it to match your server name.



cat ~/.ssh/id_rsa.pub | ssh user@hostname 'cat >> .ssh/authorized_keys'





share|improve this answer





























    up vote
    5
    down vote













    Append the public key (id_[rd]sa.pub) for your source machine (where you're sshing from) to the ~/.ssh/authorized_keys file of the destination server for the username you want to ssh into. If you've lost the public key, you'll want to create a new one with ssh-keygen. Using the default arguments for that should be ok for most purposes. If you need more detailed instructions, there are thousands of tutorials you can google.






    share|improve this answer



























      up vote
      0
      down vote













      ssh -i ~/path/to/key.pem username@remote.address.com





      share|improve this answer








      New contributor




      Bahman.A is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.

















        Your Answer







        StackExchange.ready(function()
        var channelOptions =
        tags: "".split(" "),
        id: "106"
        ;
        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',
        convertImagesToLinks: false,
        noModals: false,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: null,
        bindNavPrevention: true,
        postfix: "",
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        );



        );













         

        draft saved


        draft discarded


















        StackExchange.ready(
        function ()
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f23291%2fhow-to-ssh-to-remote-server-using-a-private-key%23new-answer', 'question_page');

        );

        Post as a guest






























        5 Answers
        5






        active

        oldest

        votes








        5 Answers
        5






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes








        up vote
        51
        down vote



        accepted










        You need your SSH public key and you will need your ssh private key. Keys can be generated with ssh_keygen.
        The private key must be kept on Server 1 and the public key must be stored on Server 2.



        This is completly described in the manpage of openssh, so I will quote a lot of it. You should read the section 'Authentication'. Also the openSSH manual should be really helpful: http://www.openssh.org/manual.html



        Please be careful with ssh because this affects the security of your server.



        From man ssh:



         ~/.ssh/identity
        ~/.ssh/id_dsa
        ~/.ssh/id_rsa
        Contains the private key for authentication. These files contain
        sensitive data and should be readable by the user but not acces-
        sible by others (read/write/execute). ssh will simply ignore a
        private key file if it is accessible by others. It is possible
        to specify a passphrase when generating the key which will be
        used to encrypt the sensitive part of this file using 3DES.

        ~/.ssh/identity.pub
        ~/.ssh/id_dsa.pub
        ~/.ssh/id_rsa.pub
        Contains the public key for authentication. These files are not
        sensitive and can (but need not) be readable by anyone.


        This means you can store your private key in your home directory in .ssh. Another possibility is to tell ssh via the -i parameter switch to use a special identity file.
        Also from man ssh:



         -i identity_file
        Selects a file from which the identity (private key) for RSA or
        DSA authentication is read. The default is ~/.ssh/identity for
        protocol version 1, and ~/.ssh/id_rsa and ~/.ssh/id_dsa for pro-
        tocol version 2. Identity files may also be specified on a per-
        host basis in the configuration file. It is possible to have
        multiple -i options (and multiple identities specified in config-
        uration files).


        This is for the private key. Now you need to introduce your public key on Server 2. Again a quote from man ssh:



         ~/.ssh/authorized_keys
        Lists the public keys (RSA/DSA) that can be used for logging in
        as this user. The format of this file is described in the
        sshd(8) manual page. This file is not highly sensitive, but the
        recommended permissions are read/write for the user, and not
        accessible by others.


        The easiest way to achive that is to copy the file to Server 2 and append it to the authorized_keys file:



        scp -p your_pub_key.pub user@host:
        ssh user@host
        host$ cat id_dsa.pub >> ~/.ssh/authorized_keys


        Authorisation via public key must be allowed for the ssh daemon, see man ssh_config. Usually this can be done by adding the following statement to the config file:



        PubkeyAuthentication yes





        share|improve this answer


















        • 6




          Hi thank you for the effort but I only need this. ssh -i keyfile thanks!
          – Aivan Monceller
          Oct 25 '11 at 20:59






        • 3




          After generating the key, the easiest and recommended way to install it on the server is with ssh-copy-id: ssh-copy-id -i ~/.ssh/foo.id_rsa remote.example.com.
          – Gilles
          Oct 26 '11 at 7:09






        • 2




          It's interesting how everyone forgets to mention that u need to run ssh-add after creating a key on the computer you are connecting from. that is what causes a headache to most people.
          – Luka
          Sep 19 '17 at 21:49










        • IMPORTANT NOTE: The client can have many private keys and select based on an arbitrary name in their private ~/.ssh/config file where Host= gives the arbitrary name, HostName gives either a name or IP address, Port= the target port, User is destination username, and ItentityFile= points to the private key file. This feature set is often overlooked and is THE solution to many configuration issues, such as having multiple key-pairs that otherwise collide in name-space.
          – Richard T
          Aug 25 at 22:46














        up vote
        51
        down vote



        accepted










        You need your SSH public key and you will need your ssh private key. Keys can be generated with ssh_keygen.
        The private key must be kept on Server 1 and the public key must be stored on Server 2.



        This is completly described in the manpage of openssh, so I will quote a lot of it. You should read the section 'Authentication'. Also the openSSH manual should be really helpful: http://www.openssh.org/manual.html



        Please be careful with ssh because this affects the security of your server.



        From man ssh:



         ~/.ssh/identity
        ~/.ssh/id_dsa
        ~/.ssh/id_rsa
        Contains the private key for authentication. These files contain
        sensitive data and should be readable by the user but not acces-
        sible by others (read/write/execute). ssh will simply ignore a
        private key file if it is accessible by others. It is possible
        to specify a passphrase when generating the key which will be
        used to encrypt the sensitive part of this file using 3DES.

        ~/.ssh/identity.pub
        ~/.ssh/id_dsa.pub
        ~/.ssh/id_rsa.pub
        Contains the public key for authentication. These files are not
        sensitive and can (but need not) be readable by anyone.


        This means you can store your private key in your home directory in .ssh. Another possibility is to tell ssh via the -i parameter switch to use a special identity file.
        Also from man ssh:



         -i identity_file
        Selects a file from which the identity (private key) for RSA or
        DSA authentication is read. The default is ~/.ssh/identity for
        protocol version 1, and ~/.ssh/id_rsa and ~/.ssh/id_dsa for pro-
        tocol version 2. Identity files may also be specified on a per-
        host basis in the configuration file. It is possible to have
        multiple -i options (and multiple identities specified in config-
        uration files).


        This is for the private key. Now you need to introduce your public key on Server 2. Again a quote from man ssh:



         ~/.ssh/authorized_keys
        Lists the public keys (RSA/DSA) that can be used for logging in
        as this user. The format of this file is described in the
        sshd(8) manual page. This file is not highly sensitive, but the
        recommended permissions are read/write for the user, and not
        accessible by others.


        The easiest way to achive that is to copy the file to Server 2 and append it to the authorized_keys file:



        scp -p your_pub_key.pub user@host:
        ssh user@host
        host$ cat id_dsa.pub >> ~/.ssh/authorized_keys


        Authorisation via public key must be allowed for the ssh daemon, see man ssh_config. Usually this can be done by adding the following statement to the config file:



        PubkeyAuthentication yes





        share|improve this answer


















        • 6




          Hi thank you for the effort but I only need this. ssh -i keyfile thanks!
          – Aivan Monceller
          Oct 25 '11 at 20:59






        • 3




          After generating the key, the easiest and recommended way to install it on the server is with ssh-copy-id: ssh-copy-id -i ~/.ssh/foo.id_rsa remote.example.com.
          – Gilles
          Oct 26 '11 at 7:09






        • 2




          It's interesting how everyone forgets to mention that u need to run ssh-add after creating a key on the computer you are connecting from. that is what causes a headache to most people.
          – Luka
          Sep 19 '17 at 21:49










        • IMPORTANT NOTE: The client can have many private keys and select based on an arbitrary name in their private ~/.ssh/config file where Host= gives the arbitrary name, HostName gives either a name or IP address, Port= the target port, User is destination username, and ItentityFile= points to the private key file. This feature set is often overlooked and is THE solution to many configuration issues, such as having multiple key-pairs that otherwise collide in name-space.
          – Richard T
          Aug 25 at 22:46












        up vote
        51
        down vote



        accepted







        up vote
        51
        down vote



        accepted






        You need your SSH public key and you will need your ssh private key. Keys can be generated with ssh_keygen.
        The private key must be kept on Server 1 and the public key must be stored on Server 2.



        This is completly described in the manpage of openssh, so I will quote a lot of it. You should read the section 'Authentication'. Also the openSSH manual should be really helpful: http://www.openssh.org/manual.html



        Please be careful with ssh because this affects the security of your server.



        From man ssh:



         ~/.ssh/identity
        ~/.ssh/id_dsa
        ~/.ssh/id_rsa
        Contains the private key for authentication. These files contain
        sensitive data and should be readable by the user but not acces-
        sible by others (read/write/execute). ssh will simply ignore a
        private key file if it is accessible by others. It is possible
        to specify a passphrase when generating the key which will be
        used to encrypt the sensitive part of this file using 3DES.

        ~/.ssh/identity.pub
        ~/.ssh/id_dsa.pub
        ~/.ssh/id_rsa.pub
        Contains the public key for authentication. These files are not
        sensitive and can (but need not) be readable by anyone.


        This means you can store your private key in your home directory in .ssh. Another possibility is to tell ssh via the -i parameter switch to use a special identity file.
        Also from man ssh:



         -i identity_file
        Selects a file from which the identity (private key) for RSA or
        DSA authentication is read. The default is ~/.ssh/identity for
        protocol version 1, and ~/.ssh/id_rsa and ~/.ssh/id_dsa for pro-
        tocol version 2. Identity files may also be specified on a per-
        host basis in the configuration file. It is possible to have
        multiple -i options (and multiple identities specified in config-
        uration files).


        This is for the private key. Now you need to introduce your public key on Server 2. Again a quote from man ssh:



         ~/.ssh/authorized_keys
        Lists the public keys (RSA/DSA) that can be used for logging in
        as this user. The format of this file is described in the
        sshd(8) manual page. This file is not highly sensitive, but the
        recommended permissions are read/write for the user, and not
        accessible by others.


        The easiest way to achive that is to copy the file to Server 2 and append it to the authorized_keys file:



        scp -p your_pub_key.pub user@host:
        ssh user@host
        host$ cat id_dsa.pub >> ~/.ssh/authorized_keys


        Authorisation via public key must be allowed for the ssh daemon, see man ssh_config. Usually this can be done by adding the following statement to the config file:



        PubkeyAuthentication yes





        share|improve this answer














        You need your SSH public key and you will need your ssh private key. Keys can be generated with ssh_keygen.
        The private key must be kept on Server 1 and the public key must be stored on Server 2.



        This is completly described in the manpage of openssh, so I will quote a lot of it. You should read the section 'Authentication'. Also the openSSH manual should be really helpful: http://www.openssh.org/manual.html



        Please be careful with ssh because this affects the security of your server.



        From man ssh:



         ~/.ssh/identity
        ~/.ssh/id_dsa
        ~/.ssh/id_rsa
        Contains the private key for authentication. These files contain
        sensitive data and should be readable by the user but not acces-
        sible by others (read/write/execute). ssh will simply ignore a
        private key file if it is accessible by others. It is possible
        to specify a passphrase when generating the key which will be
        used to encrypt the sensitive part of this file using 3DES.

        ~/.ssh/identity.pub
        ~/.ssh/id_dsa.pub
        ~/.ssh/id_rsa.pub
        Contains the public key for authentication. These files are not
        sensitive and can (but need not) be readable by anyone.


        This means you can store your private key in your home directory in .ssh. Another possibility is to tell ssh via the -i parameter switch to use a special identity file.
        Also from man ssh:



         -i identity_file
        Selects a file from which the identity (private key) for RSA or
        DSA authentication is read. The default is ~/.ssh/identity for
        protocol version 1, and ~/.ssh/id_rsa and ~/.ssh/id_dsa for pro-
        tocol version 2. Identity files may also be specified on a per-
        host basis in the configuration file. It is possible to have
        multiple -i options (and multiple identities specified in config-
        uration files).


        This is for the private key. Now you need to introduce your public key on Server 2. Again a quote from man ssh:



         ~/.ssh/authorized_keys
        Lists the public keys (RSA/DSA) that can be used for logging in
        as this user. The format of this file is described in the
        sshd(8) manual page. This file is not highly sensitive, but the
        recommended permissions are read/write for the user, and not
        accessible by others.


        The easiest way to achive that is to copy the file to Server 2 and append it to the authorized_keys file:



        scp -p your_pub_key.pub user@host:
        ssh user@host
        host$ cat id_dsa.pub >> ~/.ssh/authorized_keys


        Authorisation via public key must be allowed for the ssh daemon, see man ssh_config. Usually this can be done by adding the following statement to the config file:



        PubkeyAuthentication yes






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Sep 22 '17 at 12:06









        Ben Cox

        1032




        1032










        answered Oct 25 '11 at 19:43









        echox

        12.3k23853




        12.3k23853







        • 6




          Hi thank you for the effort but I only need this. ssh -i keyfile thanks!
          – Aivan Monceller
          Oct 25 '11 at 20:59






        • 3




          After generating the key, the easiest and recommended way to install it on the server is with ssh-copy-id: ssh-copy-id -i ~/.ssh/foo.id_rsa remote.example.com.
          – Gilles
          Oct 26 '11 at 7:09






        • 2




          It's interesting how everyone forgets to mention that u need to run ssh-add after creating a key on the computer you are connecting from. that is what causes a headache to most people.
          – Luka
          Sep 19 '17 at 21:49










        • IMPORTANT NOTE: The client can have many private keys and select based on an arbitrary name in their private ~/.ssh/config file where Host= gives the arbitrary name, HostName gives either a name or IP address, Port= the target port, User is destination username, and ItentityFile= points to the private key file. This feature set is often overlooked and is THE solution to many configuration issues, such as having multiple key-pairs that otherwise collide in name-space.
          – Richard T
          Aug 25 at 22:46












        • 6




          Hi thank you for the effort but I only need this. ssh -i keyfile thanks!
          – Aivan Monceller
          Oct 25 '11 at 20:59






        • 3




          After generating the key, the easiest and recommended way to install it on the server is with ssh-copy-id: ssh-copy-id -i ~/.ssh/foo.id_rsa remote.example.com.
          – Gilles
          Oct 26 '11 at 7:09






        • 2




          It's interesting how everyone forgets to mention that u need to run ssh-add after creating a key on the computer you are connecting from. that is what causes a headache to most people.
          – Luka
          Sep 19 '17 at 21:49










        • IMPORTANT NOTE: The client can have many private keys and select based on an arbitrary name in their private ~/.ssh/config file where Host= gives the arbitrary name, HostName gives either a name or IP address, Port= the target port, User is destination username, and ItentityFile= points to the private key file. This feature set is often overlooked and is THE solution to many configuration issues, such as having multiple key-pairs that otherwise collide in name-space.
          – Richard T
          Aug 25 at 22:46







        6




        6




        Hi thank you for the effort but I only need this. ssh -i keyfile thanks!
        – Aivan Monceller
        Oct 25 '11 at 20:59




        Hi thank you for the effort but I only need this. ssh -i keyfile thanks!
        – Aivan Monceller
        Oct 25 '11 at 20:59




        3




        3




        After generating the key, the easiest and recommended way to install it on the server is with ssh-copy-id: ssh-copy-id -i ~/.ssh/foo.id_rsa remote.example.com.
        – Gilles
        Oct 26 '11 at 7:09




        After generating the key, the easiest and recommended way to install it on the server is with ssh-copy-id: ssh-copy-id -i ~/.ssh/foo.id_rsa remote.example.com.
        – Gilles
        Oct 26 '11 at 7:09




        2




        2




        It's interesting how everyone forgets to mention that u need to run ssh-add after creating a key on the computer you are connecting from. that is what causes a headache to most people.
        – Luka
        Sep 19 '17 at 21:49




        It's interesting how everyone forgets to mention that u need to run ssh-add after creating a key on the computer you are connecting from. that is what causes a headache to most people.
        – Luka
        Sep 19 '17 at 21:49












        IMPORTANT NOTE: The client can have many private keys and select based on an arbitrary name in their private ~/.ssh/config file where Host= gives the arbitrary name, HostName gives either a name or IP address, Port= the target port, User is destination username, and ItentityFile= points to the private key file. This feature set is often overlooked and is THE solution to many configuration issues, such as having multiple key-pairs that otherwise collide in name-space.
        – Richard T
        Aug 25 at 22:46




        IMPORTANT NOTE: The client can have many private keys and select based on an arbitrary name in their private ~/.ssh/config file where Host= gives the arbitrary name, HostName gives either a name or IP address, Port= the target port, User is destination username, and ItentityFile= points to the private key file. This feature set is often overlooked and is THE solution to many configuration issues, such as having multiple key-pairs that otherwise collide in name-space.
        – Richard T
        Aug 25 at 22:46












        up vote
        13
        down vote













        I used ssh with -i option to add your key here.



        If you want to pass arg1,arg2 with .sh file, just pass it after .sh file and use a use space to separate it.



        ssh -i home/avr/new.pem ar@231.221.54.8 "/var/www/beta/betatolive.sh mmin 30"






        share|improve this answer






















        • Don't forget to set the right permissions: chmod 600 home/avr/new.pem
          – Brian Haak
          Jun 22 '17 at 3:34















        up vote
        13
        down vote













        I used ssh with -i option to add your key here.



        If you want to pass arg1,arg2 with .sh file, just pass it after .sh file and use a use space to separate it.



        ssh -i home/avr/new.pem ar@231.221.54.8 "/var/www/beta/betatolive.sh mmin 30"






        share|improve this answer






















        • Don't forget to set the right permissions: chmod 600 home/avr/new.pem
          – Brian Haak
          Jun 22 '17 at 3:34













        up vote
        13
        down vote










        up vote
        13
        down vote









        I used ssh with -i option to add your key here.



        If you want to pass arg1,arg2 with .sh file, just pass it after .sh file and use a use space to separate it.



        ssh -i home/avr/new.pem ar@231.221.54.8 "/var/www/beta/betatolive.sh mmin 30"






        share|improve this answer














        I used ssh with -i option to add your key here.



        If you want to pass arg1,arg2 with .sh file, just pass it after .sh file and use a use space to separate it.



        ssh -i home/avr/new.pem ar@231.221.54.8 "/var/www/beta/betatolive.sh mmin 30"







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jan 13 at 0:07









        Jeff Schaller

        33.8k851113




        33.8k851113










        answered May 27 '16 at 7:06









        Avinash Raut

        23324




        23324











        • Don't forget to set the right permissions: chmod 600 home/avr/new.pem
          – Brian Haak
          Jun 22 '17 at 3:34

















        • Don't forget to set the right permissions: chmod 600 home/avr/new.pem
          – Brian Haak
          Jun 22 '17 at 3:34
















        Don't forget to set the right permissions: chmod 600 home/avr/new.pem
        – Brian Haak
        Jun 22 '17 at 3:34





        Don't forget to set the right permissions: chmod 600 home/avr/new.pem
        – Brian Haak
        Jun 22 '17 at 3:34











        up vote
        12
        down vote













        The first thing you’ll need to do is make sure you’ve run the keygen command to generate the keys:



        ssh-keygen -t rsa


        Then use this command to push the key to the remote server, modifying it to match your server name.



        cat ~/.ssh/id_rsa.pub | ssh user@hostname 'cat >> .ssh/authorized_keys'





        share|improve this answer


























          up vote
          12
          down vote













          The first thing you’ll need to do is make sure you’ve run the keygen command to generate the keys:



          ssh-keygen -t rsa


          Then use this command to push the key to the remote server, modifying it to match your server name.



          cat ~/.ssh/id_rsa.pub | ssh user@hostname 'cat >> .ssh/authorized_keys'





          share|improve this answer
























            up vote
            12
            down vote










            up vote
            12
            down vote









            The first thing you’ll need to do is make sure you’ve run the keygen command to generate the keys:



            ssh-keygen -t rsa


            Then use this command to push the key to the remote server, modifying it to match your server name.



            cat ~/.ssh/id_rsa.pub | ssh user@hostname 'cat >> .ssh/authorized_keys'





            share|improve this answer














            The first thing you’ll need to do is make sure you’ve run the keygen command to generate the keys:



            ssh-keygen -t rsa


            Then use this command to push the key to the remote server, modifying it to match your server name.



            cat ~/.ssh/id_rsa.pub | ssh user@hostname 'cat >> .ssh/authorized_keys'






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Aug 3 '13 at 8:01









            Mat

            38k7115124




            38k7115124










            answered Aug 3 '13 at 7:43









            Anubhav Singh

            22922




            22922




















                up vote
                5
                down vote













                Append the public key (id_[rd]sa.pub) for your source machine (where you're sshing from) to the ~/.ssh/authorized_keys file of the destination server for the username you want to ssh into. If you've lost the public key, you'll want to create a new one with ssh-keygen. Using the default arguments for that should be ok for most purposes. If you need more detailed instructions, there are thousands of tutorials you can google.






                share|improve this answer
























                  up vote
                  5
                  down vote













                  Append the public key (id_[rd]sa.pub) for your source machine (where you're sshing from) to the ~/.ssh/authorized_keys file of the destination server for the username you want to ssh into. If you've lost the public key, you'll want to create a new one with ssh-keygen. Using the default arguments for that should be ok for most purposes. If you need more detailed instructions, there are thousands of tutorials you can google.






                  share|improve this answer






















                    up vote
                    5
                    down vote










                    up vote
                    5
                    down vote









                    Append the public key (id_[rd]sa.pub) for your source machine (where you're sshing from) to the ~/.ssh/authorized_keys file of the destination server for the username you want to ssh into. If you've lost the public key, you'll want to create a new one with ssh-keygen. Using the default arguments for that should be ok for most purposes. If you need more detailed instructions, there are thousands of tutorials you can google.






                    share|improve this answer












                    Append the public key (id_[rd]sa.pub) for your source machine (where you're sshing from) to the ~/.ssh/authorized_keys file of the destination server for the username you want to ssh into. If you've lost the public key, you'll want to create a new one with ssh-keygen. Using the default arguments for that should be ok for most purposes. If you need more detailed instructions, there are thousands of tutorials you can google.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Oct 25 '11 at 19:40









                    Kevin

                    26.2k95897




                    26.2k95897




















                        up vote
                        0
                        down vote













                        ssh -i ~/path/to/key.pem username@remote.address.com





                        share|improve this answer








                        New contributor




                        Bahman.A is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                        Check out our Code of Conduct.





















                          up vote
                          0
                          down vote













                          ssh -i ~/path/to/key.pem username@remote.address.com





                          share|improve this answer








                          New contributor




                          Bahman.A is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.



















                            up vote
                            0
                            down vote










                            up vote
                            0
                            down vote









                            ssh -i ~/path/to/key.pem username@remote.address.com





                            share|improve this answer








                            New contributor




                            Bahman.A is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.









                            ssh -i ~/path/to/key.pem username@remote.address.com






                            share|improve this answer








                            New contributor




                            Bahman.A is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.









                            share|improve this answer



                            share|improve this answer






                            New contributor




                            Bahman.A is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.









                            answered 13 mins ago









                            Bahman.A

                            11




                            11




                            New contributor




                            Bahman.A is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.





                            New contributor





                            Bahman.A is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.






                            Bahman.A is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.



























                                 

                                draft saved


                                draft discarded















































                                 


                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f23291%2fhow-to-ssh-to-remote-server-using-a-private-key%23new-answer', 'question_page');

                                );

                                Post as a guest













































































                                Popular posts from this blog

                                How to check contact read email or not when send email to Individual?

                                Bahrain

                                Postfix configuration issue with fips on centos 7; mailgun relay