{"id":2314,"date":"2016-10-19T14:26:54","date_gmt":"2016-10-19T11:26:54","guid":{"rendered":"https:\/\/upcloud.com\/global\/us\/resources\/tutorials\/reset-root-password-cloud-server\/"},"modified":"2016-10-19T14:26:54","modified_gmt":"2016-10-19T11:26:54","slug":"reset-root-password-cloud-server","status":"publish","type":"tutorial","link":"https:\/\/upcloud.com\/global\/resources\/tutorials\/reset-root-password-cloud-server\/","title":{"rendered":"How to reset root password on Cloud Server"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Strong system security requires equally strong passwords, which, in turn, make the passwords more difficult to remember. In such case that the password for the Linux root user account is lost without an alternative sign-in method like an <a href=\"https:\/\/upcloud.com\/global\/community\/tutorials\/\n\/managing-ssh-keys\/\" target=\"_blank\" rel=\"noopener\">SSH key<\/a>, you might end up locked out of your own system. Luckily, resetting the root password of your cloud server is fairly straightforward and will only take a few minutes to complete.<\/p>\n\n\n\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link wp-element-button\" href=\"https:\/\/signup.upcloud.com\/\">Test hosting on UpCloud!<\/a><\/div>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Deploying a temporary Linux host<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To gain access to your old root account, you will need to be able to boot a system to a command line. A common way to do this for Linux computers is to boot into the GRUB menu, but this might prove slightly difficult on cloud servers where you have no physical access to the system. Instead, you can take advantage of the virtual nature of the cloud environment and simply create a new server to mount the old disk device in.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Start by logging into your UpCloud control panel and&nbsp;<a href=\"https:\/\/hub.upcloud.com\/deploy\" target=\"_blank\" rel=\"noopener\">deploying a new server<\/a>.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Select the same availability zone as your old server.<\/li>\n\n\n\n<li>Pick a configuration, the smallest is fine.<\/li>\n\n\n\n<li>Select whichever Linux distribution you wish. Usually, it is easiest to use the same OS as your&nbsp;old system.<\/li>\n\n\n\n<li>Add your SSH keys. Not highly important as you will only need to log in once.<\/li>\n\n\n\n<li>Use a simple initialization script to shut down the server after the first boot. It will save you some time as the server must be powered down to make changes to the storage.\n<pre>shutdown -h 1<\/pre>\n<figure><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-13927 size-full\" src=\"https:\/\/upcloud.com\/media\/shutdown-init-script.png\" alt=\"Script to shutdown after deployment\" width=\"884\" height=\"468\" \/><\/figure><p><\/p>\n<\/li>\n\n\n\n<li>Once the setup is ready, click the <i>Deploy&nbsp;<\/i>button at the bottom of the page.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">The deployment process will only take a&nbsp;moment, but you do not have to wait for it to complete. Continue below with the next part.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Moving the old system disk to the temporary host<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In the meanwhile, as your new server is being deployed, shut down your old server at the control panel. If the server was installed using a custom system image, you may need to use the forced shutdown command.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><a href=\"https:\/\/upcloud.com\/global\/community\/\n\/tutorials\/taking-backups\/\" target=\"_blank\" rel=\"noopener\">We recommend taking a backup of your server before resetting the&nbsp;root password<\/a><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">With the server shut down, go to the <em>Storage<\/em> tab in your server settings.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Make sure the storage device is named so that you will be able to recognise it later. You can rename the device by clicking the <i>pencil<\/i> icon, entering a new name, then clicking the accept icon and afterwards the <em>Save changes<\/em> button to confirm.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/upcloud.com\/media\/rename-disk.png\" alt=\"Rename disk\" class=\"wp-image-5724\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Then, free up the OS disk device from the host by clicking the <em>Detach<\/em> button. If you have multiple disks, leave the other devices as they are. When attaching the OS disk again after the password reset, it will be set correctly as the first device.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/upcloud.com\/media\/detach-storage.png\" alt=\"Detach storage\" class=\"wp-image-5725\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Next, open the server settings of the temporary server and go to the <em>Storage<\/em> tab there.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Click on the&nbsp;<em>Add new device<\/em>&nbsp;button at the end of the storage list.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the new storage device window, select A<em>ttach existing device<\/em>, then find the device you just detached in the <em>Devices list<\/em>. Once you have selected the right disk, click the&nbsp;<em>Add a storage device<\/em> button underneath to confirm.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/upcloud.com\/media\/attach-password-reset-device.png\" alt=\"Attach password reset device\" class=\"wp-image-5726\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">When the disk has been attached successfully, boot up the server and log in over SSH with the root user of the temporary host.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Resetting the root password<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">When logged into the temporary server, check that you can see the old system disk.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">lsblk\n\nNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT\nvda 253:0 0 25G 0 disk\n\u2514\u2500vda1 253:1 0 25G 0 part \/\nvdb 253:16 0 25G 0 disk\n\u2514\u2500vdb1 253:17 0 25G 0 part<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The first device <em>vda<\/em>&nbsp;in the above example is the system disk running the temporary server and the second <em>vdb<\/em> is your original system device. To access the second storage, you will need to mount it in the running system.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mount \/dev\/vdb1 \/mnt<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Then change to the root environment of the original system.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">chroot \/mnt<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You can now change the root password with the usual command. Enter the new password twice to confirm.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">passwd<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Once you have reset the password, exit the mounting system and shut down the temporary host so that you can return the old system disk where it belongs.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">exit\n\nshutdown -h now<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Returning the system storage<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">When the temporary server has been powered down, you can detach the system device original in the server settings and Storage tab as you did before. Then reattach it to its original host.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/upcloud.com\/media\/reattached-original-server.png\" alt=\"Storage reattached on the original server\" class=\"wp-image-5727\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Then start the original server again.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You should now be able to log in using the root account with the password you just set and gain normal access to your server.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">After confirming that the password was reset successfully, the temporary server and storage device can be deleted.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/upcloud.com\/media\/delete-temporary-server.png\" alt=\"Delete the temporary server\" class=\"wp-image-5728\" \/><\/figure>\n","protected":false},"author":3,"featured_media":27304,"comment_status":"open","ping_status":"closed","template":"","community-category":[253,247],"class_list":["post-2314","tutorial","type-tutorial","status-publish","has-post-thumbnail","hentry"],"acf":[],"_links":{"self":[{"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/tutorial\/2314","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/tutorial"}],"about":[{"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/types\/tutorial"}],"author":[{"embeddable":true,"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/comments?post=2314"}],"version-history":[{"count":0,"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/tutorial\/2314\/revisions"}],"wp:attachment":[{"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/media?parent=2314"}],"wp:term":[{"taxonomy":"community-category","embeddable":true,"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/community-category?post=2314"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}