Linux allow root ssh

Allow root account to use SSH (openssh)

Q. Previous admin blocked root access to ssh server. How do I allow root account access to ssh server?

A. Allowing direct root access over ssh is a security risk. However following steps will allow you to login as root over ssh session:

Open sshd_config file:
# vi /etc/ssh/sshd_config

Find out line that read as follows:
PermitRootLogin no
Set it as follows:
PermitRootLogin yes

  • No ads and tracking
  • In-depth guides for developers and sysadmins at Opensourceflare✨
  • Join my Patreon to support independent content creators and start reading latest guides:
    • How to set up Redis sentinel cluster on Ubuntu or Debian Linux
    • How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
    • How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
    • A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
    • How to protect Linux against rogue USB devices using USBGuard

Join Patreon

Find out line that read as follows (this line may not exists in your configuration):
DenyUsers root user2 user3
Set is as follows:
DenyUsers user2 user3

Save and close the file. Restart the sshd:
# /etc/init.d/ssh restart

🐧 Get the latest tutorials on Linux, Open Source & DevOps via

Category List of Unix and Linux commands
Documentation help • mandb • man • pinfo
Disk space analyzers df • duf • ncdu • pydf
File Management cat • cp • less • mkdir • more • tree
Firewall Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04
Linux Desktop Apps Skype • Spotify • VLC 3
Modern utilities bat • exa
Network Utilities NetHogs • dig • host • ip • nmap
OpenVPN CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04
Package Manager apk • apt
Processes Management bg • chroot • cron • disown • fg • glances • gtop • jobs • killall • kill • pidof • pstree • pwdx • time • vtop
Searching ag • grep • whereis • which
Shell builtins compgen • echo • printf
Text processing cut • rev
User Information groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w
WireGuard VPN Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04

Comments on this entry are closed.

Your command for sshd is incorrect – should be:
# /etc/init.d/sshd restart

You were missing the “d” for sshd

i guess you can also use : service sshd restart

It can be ssh or sshd – it depends upon your Linux distro. Redhat/CentOS/FC use sshd and ssh used by Debian or Ubuntu and so on..

Most people would be wanting to know how to enable this, to secure their boxes. Perhaps the unknown asker doesn’t know how to use sudo or su properly so that you can log in remotely via a safe, unprivileged user account and then, once the connection is secure, issue privileged commands or switch to a privileged account? Or perhaps s/he wishes to have unrestricted access to the computer with no tracking of who issued what commands?

Sometimes, people need more convenience than safety.

just do a ” svcadm restart ssh”

That only would work on Solaris 🙂

I wanted to enable root login via ssh in my server, but couldn’t see the below file on the server. Please help.

One year late, but maybe it will be helpful for somebody else:
it’s possible that you don’t see the sshd_config file because you don’t have the OpenSSH suite (or any other ssh servers) installed on the remote machine.

You also need to add root to Allowusers

I did The PermitRootLogin thing and also Allowusers…. still not working!! what goes wrong?

how can you change sshd_config file to enable root ssh access, since you can not login to ssh with root?

I can only login in ssh with a user password, i have the root password too but first i have to change that file wich is readonly and I can not change it, I tried “chmod a=rwx sshd_config” but “operation not permitted” ..

This assumes that you have local root access to your server. For Redhat based Linux, you ssh as a non-privileged user, su – and then you become root, and then apply the changes. For Debian based Linux, ssh as a non-privileged user, sudo -i become root, and then apply the changes.

The whole point in disabling remote root access is to reduce the possibility of your server getting broken into if your root password is weak or server is not up to date in security/updated software.
Remember not to enable this on a server that has Internet connection and can be reached over the Internet, unless you absolutely have to, and if you did, I strongly recommend tightening your iptables rules, and use something like fail2ban, along with log watch/snort, …etc.

Источник

Disable or Enable SSH Root Login and Limit SSH Access in Linux

Today, everyone knows that Linux systems comes with root user access and by default the root access is enabled for outside world. For security reason it’s not a good idea to have ssh root access enabled for unauthorized users. Because any hacker can try to brute force your password and gain access to your system.

Disable SSH Root Login

So, its better to have another account that you regularly use and then switch to root user by using ‘su –‘ command when necessary. Before we start, make sure you have a regular user account and with that you su or sudo to gain root access.

In Linux, it’s very easy to create separate account, login as root user and simply run the ‘adduser‘ command to create separate user. Once user is created, just follow the below steps to disable root login via SSH.

We use sshd master configuration file to disable root login and this will may decrease and prevent the hacker from gaining root access to your Linux box. We also see how to enable root access again as well as how to limit ssh access based on users list.

Disable SSH Root Login

To disable root login, open the main ssh configuration file /etc/ssh/sshd_config with your choice of editor.

Search for the following line in the file.

Remove the ‘#‘ from the beginning of the line. Make the line look like similar to this.

Next, we need to restart the SSH daemon service.

Now try to login with root user, you will get “Access Denied” error.

So, from now onwards login as normal user and then use ‘su’ command to switch to root user.

Enable SSH Root Login

To enable ssh root logging, open the file /etc/ssh/sshd_config.

Search for the following line and put the ‘#‘ at the beginning and save the file.

Restart the sshd service.

Now try to login with root user.

Limit SSH User Logins

If you have large number of user accounts on the systems, then it makes sense that we limit remote access to those users who really need it. Open the /etc/ssh/sshd_config file.

Add an AllowUsers line at the bottom of the file with a space separated by list of usernames. For example, user tecmint and sheena both have access to remote ssh.

Now restart ssh service.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

We are thankful for your never ending support.

Источник

Включить вход под Root в Ubuntu для SSH и SFTP

Доступно рассказываем о том как разрешить в Ubuntu заходить под root по SSH и SFTP? Вот что для этого нужно это…

По умолчанию в Ubuntu учетная запись root отключена и повсюду используется команда sudo. Если вам необходимо перемещать большое количество файлов или работать под root вам понадобиться включить root и после разрешить логинится в системе.

Включаем Root в Ubuntu Server

Создаем пароль для учетной записи Root:

и вводим 2 раза придуманный вами пароль.

Разрешаем логинится под Root в Ubuntu Server

Убедитесь что ssh-server у вас установлен в Ubuntu Server

Несмотря на то, что учетная запись есть и пароль тоже есть, войти с учетной записью root по SSH и SFTP не получится. Необходимо отредактировать файл sshd_config :

И изменить строчку

После вставки нажать:

  • комбинацию клавиш CTRL+O, а затем ENTER
  • комбинацию клавиш CTRL+X

Перезапустите service ssh, чтобы все изменения вступили в силу:

Теперь вы можете выполнить в Ubuntu вход под Root по SSH и SFTP!

У вас еще остались вопросы? Пишите их в комментариях, рассказывайте, что у вас получилось или наоборот!

Вот и все! Больше полезных статей и инструкций читайте в разделе Статьи и Хаки Android. Оставайтесь вместе с сайтом Android +1, дальше будет еще интересней!

Источник

Enable Root Login via SSH In Ubuntu

By default, SSH on Ubuntu comes configured in a way that disables the root users log in. This was originally enabled as a security precaution which means that you cannot directly log in as the root user over SSH. However, you can usually get around the need for root ssh login by using the sudo command. In some cases, though it’s just more convenient to get directly logged in as root.

Enable root login over SSH

  1. Login to your server as root.
  2. As the root user, edit the sshd_config file found in /etc/ssh/sshd_config: vim /etc/ssh/sshd_config (For details on working with Vim check out our article here!)
  3. Add the following line to the file, you can add it anywhere but it’s good practice to find the block about authentication and add it there.
  4. Save and exit the file.
  5. Restart the SSH server:
    systemctl restart sshd
    or
    service sshd restart

And that’s it! With the new line added and the SSH server restarted, you can now connect via the root user.

In this instance, you are going to be able to login as the root user utilizing either the password or an ssh key.

When using SSH Keys, you can set the PermitRootLogin value to `without-password` instead of yes. To accomplish this, simply modify the following information noted in step 2 above instead:

PermitRootLogin without-password

This process should work on almost any version of Linux server that the sshd service is installed. If you are using a cPanel server though you can easily control this setting from the WHM interface. In these cases, it’s recommended to modify this setting from your control panel interface.

Источник

How to set up passwordless SSH access for root user [duplicate]

I need to configure a machine so software installation can be automated remotely via SSH. Following the wiki, I was able to setup SSH keys so my user can access the machine without a password, but I still need to manually enter my password when I use sudo , which obviously an automated process shouldn’t have to do.

Although my /etc/ssh/sshd_config has PermitRootLogin yes , I can’t seem to be able to log in as root, presumably because it’s not a «real» account with a separate password.

How do I configure SSH keys, so a process can remotely log in as root on Ubuntu?

4 Answers 4

Part 1 : SSH key without a password

To set up a passwordless SSH connection for the root user you need to have root access on the server. Easiest method is to temporarily allow root to log in over ssh via password. One way or another you need root access on the server to do this. If you do not have root access on the server, contact the server administrator for help.

On the client (where you ssh FROM)

First make a ssh key with no password. I highly suggest you give it a name rather then using the default

The -f option specifies a file name, foo is an example, use whatever name you wish.

When you are prompted for a password, just hit the enter key and you will generate a key with no password.

Next you need to transfer the key to the server. Easiest method is to use ssh-copy-id . To do this you must temporarily allow root to ssh into the server.

On the server (where you ssh TO)

Make sure you allow root to log in with the following syntax

Restart the server

Set a root password, use a strong one

On the client :

From the client, Transfer the key to the server

change «foo» the the name of your key and enter your server root password when asked.

Assuming it works, unset a root password and disable password login.

On the server :

Change the following :

Restart the server

On the client (Test):

You should now be able to ssh in with your key without a password and you should not be able to ssh in as any user without a key.

Part 2 : Running commands via sudo without entering a password

You configure sudo to allow you to run commands without a password.

This is answered here in two places:

Of the two, I suggest allowing as few commands as possible (first answer) rather then all commands (second answer).

You are confusing two different things:

passwordless log is used to make sure that people can’t log into your system remotely by guessing your password. If you can ssh username@machine and connect without a password, this is set up correctly, and has nothing else to do with this.

sudo is used to permit a normal user account to do something with super user permissions. This does require the user to type their password. This happens whether you are connected remotely (via passwordless or password-protected SSH) or are local on the machine. You are trying to set sudo to not ask for your password, which is not recommended, but you can learn how to do that via an answer like https://askubuntu.com/a/74083/6161

Note to future readers of this answer:

My above answer does not answer the original poster’s actual question, it describes what you should do instead. If you really want to allow remote connections directly to the root account, you need to enable the root account (see my comment below). Again, let me say DO NOT allow remote remote log-ins to your root account.

Источник

Читайте также:  Reagentc exe образ среды восстановления windows не найден
Оцените статью