Accessing a Linux Server via SSH


  • Service Provider

    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:

    [[email protected] ~]# 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.



  • 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?



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


  • Service Provider

    @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?



  • @scottalanmiller Using VMware/ESXi 6



  • @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.)


  • Service Provider

    @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



  • @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.



  • 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.



  • Do you have a network adapter? Is it enabled?



  • 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.



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



  • Yes it is. I certainly may have missed that




  • Service Provider

    Did that get you up and running?



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


  • Service Provider

    @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.



  • @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.


  • Service Provider

    @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?



  • @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.



  • @BRRABill said in Accessing a Linux Server via SSH:

    @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.

    When using Linux/UNIX, if what you have copied includes a carriage return, it will paste in the carriage return. Can be annoying to get exactly what you want to copy at times, which is why you should learn to hold shift and arrow keys to get just what you want.

    I got so used to the middle mouse button copying what was highlighted, I was kinda lost for the years between using IRIX everyday and the clickable scroll wheel appearing.


  • Service Provider

    @BRRABill said in Accessing a Linux Server via SSH:

    @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.

    No it does not. I thought maybe you were thinking this but did not want to imply it. That's a misunderstanding of what is happening. It only does that IF your Windows environment and your actions are copying a carriage return into the clipboard (which Windows does by default.) This has nothing to do with PuTTY and is all about your Windows desktop AND it only does this if YOU make it happen, it does not do that for the rest of us. We don't copy the carriage return into the clipboard unless we want it. Windows makes this easy to control as a feature, but it is an invisible feature of the Windows environment so if you are not a Windows power user, you might not be aware that there is an interface to it that you are misusing.

    PuTTY simply does what Windows tells it to do, PuTTY has no default behaviour like you are imagining.



Looks like your connection to MangoLassi was lost, please wait while we try to reconnect.