ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Accessing a Linux Server via SSH

    IT Discussion
    linux unix ssh remote access sam linux administration
    8
    22
    6.6k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • scottalanmillerS
      scottalanmiller
      last edited by scottalanmiller

      Now that we are past the basics, we are going to step back from learning the basics to address the need to easily access our Linux system from a more convenient location. Working from the console is okay for a quick test, but for any amount of work we are going to want something much more robust.

      Like Windows, Linux has many means of being accessed remotely. However, when we remove the graphical interface like we have most remote access methods become impractical or even unavailable. Over the years multiple means of accessing UNIX systems were used. Eventually, for reasons of functionality and security, the industry settled on the SSH protocol. SSH is extremely robust and powerful and we will be exploring it extensively in later lessons. For now we want to just get the basics working so that we can access our Linux lab machine without unnecessary effort.

      Because of the defaults included in CentOS combined with our installation options we should be fully ready for remote access from the Linux side and we need only attempt a connection.

      The easiest way to access any system over SSH is to do so from a machine where SSH is native such as a Linux or Mac OSX desktop. If we are on Windows we will need an SSH client, such as PuTTY, to be downloaded.

      Before we begin we will need the ip address of our Linux machine in order to access it. When we installed we had assumed that DHCP would be used, and chances are we do not remember the ip address that was displayed by the installer while we were installing or maybe the ip address has changed since then. So we need to ask the Linux machine what its ip address is. We do this on CentOS 7 using the command ip addr.

      Other systems, including CentOS before version 7, Ubuntu, OpenSuse, etc. have not moved to the new ip addr standard yet and still use the older ifconfig command. You can add ifconfig to CentOS 7 but it is recommended to learn the modern method and use ifconfig only when on other systems. Knowing both is important and in the future ifconfig will be going away across the board.

      Here is the ip addr command run on my Linux console:

      ip addr command on CentOS 7

      As you can see here, there is a bit of output. More than we really want to see. We will have to dig into it to find our useful IP address. In mine, and likely in yours, you will have two adapters: an lo and an eth0. The lo is the "loopback" adapter and not useful to us here, we will ignore that. Eth0 is the common default name for the first Ethernet adapter. This is what we want to look at here. Look for the line beginning with "inet" and our ip address should be visible there.

      Learning to look at this output will be useful. For the moment, if our system has worked consistently, then this complex command (that we will learn more about in depth later in our lessons) will give us the IP address without needing to look through the extra output of the plain ip addr command:

      [root@lab-lnx-centos ~]# ip addr | grep inet | grep eth0 | cut -d' ' -f6 | cut -d'/' -f1
      192.168.1.163
      

      In my case, the IP address is 192.168.1.163. It is not very likely that yours will be the same. If you have issues finding the IP address here, post in the thread discussion for assistance.

      Now that we have our IP address, we can attempt to log in from another machine. By default CentOS is set up to open the firewall for SSH access (actually there is no firewall installed in our specific installation, we will address this later), the SSH service is running and the root user is permitted access. So no special setup needs to be done to get things working. One of the advantages to using CentOS for our lab.

      Logging in Remotely from a UNIX System Such as Linux, BSD or Mac OSX: These are easy as SSH is installed by default. Simply open the local terminal application, often called Terminal, xterm, aterm or similar. This will be unique to your desktop environment. From the terminal session we need only type ssh [email protected] remembering to replace my IP address with the one that you have discovered for your own system.

      ssh into our linux system from UNIX

      Logging in Remotely from a Windows System Using PuTTY: There are many tools that could be used to provide an SSH client on Windows but nearly everyone uses the free PuTTY tool. It is mature, free and ubiquitous and UNIX System Admins are often expected to be familiar with it so even if you want to explore other tools, it is good to familiarize yourself with PuTTY as well. PuTTY is easy to use and very powerful. Download PuTTY here.

      Install PuTTY and run the application. It is a small and light Windows application. For now we can simply enter our details into the main screen. Enter the IP Address where it says Host Name, make sure that the protocol SSH is selected (it will default to the correct port of 22) and select "Open" at the bottom.

      Screenshots to follow.

      Once we connect from either system for the first time (and only on the first time) we will get prompted that the authenticity cannot be determined. This is the SSH security mechanism telling us that it has never seen this host before. That is good, because it has not. We need to either click "Yes" to accept adding this new host to the list of known hosts on Windows or type "yes" to accept it on our UNIX system. Once we have done this, the SSH system will remember the host and not prompt us like this again unless something changes.

      Once we have done this, we need to provide our username of "root" and our password in order to log in.

      Ta da. That is it, we are now able to connect remotely to our Linux system and can access it faster and easier than through the console. The console is really only an emergency fall back access method for initial setups and other issues.


      Logging Off of Linux Since we are logged in remotely we need a clean way to exit the system when we are done using it. This is simply the exit command. Type exit and hit enter and your session with the Linux machine will end.

      1 Reply Last reply Reply Quote 6
      • wrx7mW
        wrx7m
        last edited by

        Not a big deal but for some reason instead of eth0, which is what I am used to, my NIC is showing as eno16777984. Why would that be?

        scottalanmillerS 1 Reply Last reply Reply Quote 0
        • wrx7mW
          wrx7m
          last edited by wrx7m

          Also, what is the reasoning behind doing away with ifconfig in favor of ip addr?

          1 Reply Last reply Reply Quote 0
          • scottalanmillerS
            scottalanmiller @wrx7m
            last edited by

            @wrx7m said:

            Not a big deal but for some reason instead of eth0, which is what I am used to, my NIC is showing as eno16777984. Why would that be?

            That's pretty weird. What platform are you on?

            wrx7mW 1 Reply Last reply Reply Quote 0
            • wrx7mW
              wrx7m @scottalanmiller
              last edited by wrx7m

              @scottalanmiller Using VMware/ESXi 6

              travisdh1T 1 Reply Last reply Reply Quote 0
              • travisdh1T
                travisdh1 @wrx7m
                last edited by

                @wrx7m said:

                @scottalanmiller Using VMware/ESXi 6

                VMware isn't Linux based (anymore.)

                Also, CentOS7/RedHat have changed the naming scheme on network adapters. @scottalanmiller is keeping to basics in this series for now tho, so I don't think we want to cause all sorts of confusion (yet.)

                JaredBuschJ 1 Reply Last reply Reply Quote 0
                • JaredBuschJ
                  JaredBusch @travisdh1
                  last edited by

                  @travisdh1 said:

                  @wrx7m said:

                  @scottalanmiller Using VMware/ESXi 6

                  VMware isn't Linux based (anymore.)

                  That has nothing to do with the guest OS directly. It is more about which virtual adapter type you pick when setting up the VM.

                  Also, CentOS7/RedHat have changed the naming scheme on network adapters.

                  All of my Hyper-V ones are eth0, while my VMWare 5.5 ones are ensXX

                  coliverC 1 Reply Last reply Reply Quote 2
                  • coliverC
                    coliver @JaredBusch
                    last edited by

                    @JaredBusch said:

                    @travisdh1 said:

                    @wrx7m said:

                    @scottalanmiller Using VMware/ESXi 6

                    VMware isn't Linux based (anymore.)

                    That has nothing to do with the guest OS directly. It is more about which virtual adapter type you pick when setting up the VM.

                    Also, CentOS7/RedHat have changed the naming scheme on network adapters.

                    All of my Hyper-V ones are eth0, while my VMWare 5.5 ones are ensXX

                    I have two on XenServer one is eth0 and one is ensXX. Not sure what that would be.

                    1 Reply Last reply Reply Quote 2
                    • R
                      rfindley
                      last edited by

                      Is there any reason that my VM is not providing an ip on the 2nd option? I see in your screenshot the lo and eth0 but when my VM is showing the info after inputting ip addr I get only the lo information. There is no ip address showing up for me to work with.

                      1 Reply Last reply Reply Quote 0
                      • A
                        Alex Sage
                        last edited by

                        Do you have a network adapter? Is it enabled?

                        1 Reply Last reply Reply Quote 0
                        • R
                          rfindley
                          last edited by

                          It would appear so. Sorry but I'm a little new to this stuff. I see the connect network adapter choice in the network menu and it is selected. That being said any of the options (NAT, Bridged Adapter, etc.) I choose don't seem to connect.

                          A 1 Reply Last reply Reply Quote 0
                          • A
                            Alex Sage @rfindley
                            last edited by

                            @rfindley Is this CentOS? I think you forget to enabled the adapter. It's a common mistake 🙂

                            1 Reply Last reply Reply Quote 1
                            • R
                              rfindley
                              last edited by

                              Yes it is. I certainly may have missed that

                              A 1 Reply Last reply Reply Quote 0
                              • A
                                Alex Sage @rfindley
                                last edited by

                                @rfindley http://unix.stackexchange.com/questions/36705/why-the-default-eth0-interface-is-down-by-default-on-centos

                                1 Reply Last reply Reply Quote 1
                                • scottalanmillerS
                                  scottalanmiller
                                  last edited by

                                  Did that get you up and running?

                                  1 Reply Last reply Reply Quote 1
                                  • BRRABillB
                                    BRRABill
                                    last edited by

                                    Boy once I reconfigured the right click in PUTTY it was so much easier to use. 🙂

                                    scottalanmillerS 1 Reply Last reply Reply Quote 1
                                    • scottalanmillerS
                                      scottalanmiller @BRRABill
                                      last edited by

                                      @BRRABill said in Accessing a Linux Server via SSH:

                                      Boy once I reconfigured the right click in PUTTY it was so much easier to use. 🙂

                                      if you use it all of the time, I think that the default behaviour is really nice. It is So fast.

                                      BRRABillB 1 Reply Last reply Reply Quote 0
                                      • BRRABillB
                                        BRRABill @scottalanmiller
                                        last edited by

                                        @scottalanmiller said

                                        if you use it all of the time, I think that the default behaviour is really nice. It is So fast.

                                        But I am constantly copying stuff, and the default is to copy and paste and hit return.

                                        scottalanmillerS 1 Reply Last reply Reply Quote 0
                                        • scottalanmillerS
                                          scottalanmiller @BRRABill
                                          last edited by

                                          @BRRABill said in Accessing a Linux Server via SSH:

                                          @scottalanmiller said

                                          if you use it all of the time, I think that the default behaviour is really nice. It is So fast.

                                          But I am constantly copying stuff, and the default is to copy and paste and hit return.

                                          The default of what is to copy, paste and hit return?

                                          BRRABillB 1 Reply Last reply Reply Quote 0
                                          • BRRABillB
                                            BRRABill @scottalanmiller
                                            last edited by

                                            @scottalanmiller said

                                            The default of what is to copy, paste and hit return?

                                            PUTTY.

                                            Be default when you right click something to copy, it copies it and pastes it and then hits return.

                                            I guess perhaps just highlighting it copies it? I like the Windows method.

                                            travisdh1T scottalanmillerS 2 Replies Last reply Reply Quote 0
                                            • 1
                                            • 2
                                            • 1 / 2
                                            • First post
                                              Last post