Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794
{"id":3742,"date":"2023-05-30T11:20:55","date_gmt":"2023-05-30T11:20:55","guid":{"rendered":"https:\/\/support.aklwebhost.com\/?post_type=manual_kb&p=3742"},"modified":"2023-05-30T11:20:57","modified_gmt":"2023-05-30T11:20:57","slug":"use-an-ssh-key-with-non-root-users","status":"publish","type":"manual_kb","link":"https:\/\/support.aklwebhost.com\/knowledgebase\/use-an-ssh-key-with-non-root-users\/","title":{"rendered":"Use an SSH Key with Non-root Users"},"content":{"rendered":"\n

Introduction<\/h2>\n\n\n\n

AKLWEB HOST<\/strong> provides a feature that allows you to pre-install SSH keys when creating a new instance, so you can SSH to the instance as\u00a0root<\/strong>\u00a0with the key. However, the key doesn’t work for\u00a0non-root<\/strong>\u00a0users. This tutorial describes three methods to use SSH keys with\u00a0non-root<\/strong>\u00a0users.<\/p>\n\n\n\n

Requirements<\/h2>\n\n\n\n
    \n
  • A AKLWEB HOST<\/strong> Linux or BSD instance<\/li>\n\n\n\n
  • A non-root user account (it is example_user<\/strong> in this tutorial)<\/li>\n<\/ul>\n\n\n\n

    Option 1: Create a New SSH Key<\/h2>\n\n\n\n
      \n
    1. SSH to the instance as root.<\/li>\n\n\n\n
    2. Create an SSH key for example_user.# sudo -u example_user ssh-keygen Generating public\/private rsa key pair. Enter file in which to save the key (\/home\/example_user\/.ssh\/id_rsa): Created directory '\/home\/example_user\/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in \/home\/example_user\/.ssh\/id_rsa Your public key has been saved in \/home\/example_user\/.ssh\/id_rsa.pub<\/code><\/li>\n\n\n\n
    3. Save the private key, \/home\/example_user\/.ssh\/id_rsa<\/code>, to your computer. For example, you might copy it to your local .ssh folder as ~\/.ssh\/example_user_id_rsa<\/code>.<\/li>\n\n\n\n
    4. Delete the private key from your instance.# rm \/home\/example_user\/.ssh\/id_rsa<\/code><\/li>\n\n\n\n
    5. Rename the public key to authorized_keys<\/code>.# mv \/home\/example_user\/.ssh\/id_rsa.pub \/home\/example_user\/.ssh\/authorized_keys<\/code><\/li>\n<\/ol>\n\n\n\n

      If you saved the private key as ~\/.ssh\/example_user_id_rsa<\/code>, you can SSH to the server as your non-root example_user:<\/p>\n\n\n\n

      $ ssh -i ~\/.ssh\/example_user_id_rsa example_user@192.0.2.123\n<\/code><\/pre>\n\n\n\n

      Option 2: Move the root SSH Key to the Non-root User<\/h2>\n\n\n\n

      In this case, we’ll move the root key to the example_user, which also disables the root user’s SSH key access.<\/p>\n\n\n\n

        \n
      1. SSH to the instance as root.<\/li>\n\n\n\n
      2. Create the .ssh<\/code> directory for example_user.# mkdir \/home\/example_user\/.ssh<\/code><\/li>\n\n\n\n
      3. Move the root key to example_user’s SSH directory.# mv \/root\/.ssh\/authorized_keys \/home\/example_user\/.ssh\/<\/code><\/li>\n\n\n\n
      4. Change the ownership of the .ssh<\/code> directory from root<\/strong> to example_user<\/strong> so OpenSSH can read it.# chown -R example_user:example_user \/home\/example_user\/.ssh<\/code><\/li>\n<\/ol>\n\n\n\n

        Option 3: Use Startup Scripts<\/h2>\n\n\n\n

        If you are deploying many instances, you may use the AKLWEB HOST<\/strong>\u00a0Startup Scripts\u00a0feature to create a non-root user and move the SSH key automatically.<\/p>\n\n\n\n

        Create a Startup Script<\/h3>\n\n\n\n
          \n
        1. Select Scripts<\/strong> in the Customer Portal.<\/li>\n\n\n\n
        2. Click the plus button to create a new startup script.<\/li>\n\n\n\n
        3. Paste the following script.#!\/bin\/sh useradd -m -s \/bin\/bash example_user mv \/root\/.ssh \/home\/example_user\/ chown -R example_user:example_user \/home\/example_user\/.ssh<\/code><\/li>\n<\/ol>\n\n\n\n

          You can deploy instances with this script and one or more SSH keys. When the instance deploys, the script creates example_user, then moves the public SSH keys from root to example_user. Now you can SSH to the new instance as example_user with the keys you provided.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"","format":"standard","manualknowledgebasecat":[229,242],"manual_kb_tag":[],"_links":{"self":[{"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manual_kb\/3742"}],"collection":[{"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manual_kb"}],"about":[{"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/types\/manual_kb"}],"author":[{"embeddable":true,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/comments?post=3742"}],"version-history":[{"count":1,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manual_kb\/3742\/revisions"}],"predecessor-version":[{"id":3743,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manual_kb\/3742\/revisions\/3743"}],"wp:attachment":[{"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/media?parent=3742"}],"wp:term":[{"taxonomy":"manualknowledgebasecat","embeddable":true,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manualknowledgebasecat?post=3742"},{"taxonomy":"manual_kb_tag","embeddable":true,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manual_kb_tag?post=3742"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}