Ssh to linux with username

Getting Started With SSH in Linux

This tutorial aims to provide you with some basic knowledge about setting up and using ssh to interact with remote systems.

Thanks to the connected world we live in, you don’t need to have physical access to your server anymore. Your server can be anywhere in the world and you can connect to it from your local machine.

There are many protocols and tools which are developed for this purpose. Those include telnet and ssh. Telnet is not preferred due to security concerns. On the other hand, ssh is the popular means of securil connecting to remote systems.

In this article, I will cover some useful commands and tools a Linux user must know to use a remote system and its resources over ssh.

Note that most of the commands that you run on your personal local Linux system should be available on the remote system also (such as ls, cat, cd command etc). But running them depends on the permissions allotted to a remote user as with any Linux/UNIX system.

What is SSH?

The ssh or secure shell is a network protocol for operating networking services securely over a network. It uses encryption standards to securely connect and login to the remote system.

It stores a public key in the remote system and private key in the client system. Thes keys are produced as a pair mathematically. When both are applied to a bi-variable function, it will result in a value which will be used to check whether the pair is valid or invalid. This is the simplest explanation possible. To Learn more, please refer to this page.

Examples of using SSH

Let’s get started with setting up ssh and really cool use cases.

Generate ssh key

Websites such as GitHub and Heroku are asking for your ssh public key so that you can push/deploy code without entering a password and you don’t have such a key-pair? Don’t worry. You can generate such ssh key pair with this command:

It will prompt for a key-location (where the key will be saved) and passphrase (i.e. password). The passphrase is optional.

By default, the ssh keys are stored in .ssh directory under your home directory.

If the key-location is DIR_PATH/keypairforssh, there will be two files

1 is the private key file which you must not share with anyone
2 is the public key file which can be shared with remote systems (by means of other trusted communication such as mail, physical transfer, and other secured communication tools) and services such as Github, Heroku for the respective use cases. Be sure to check thoroughly about the service for which you are connecting.

Add private key to the key-agent

When the key pair is created, it justs exists as a set of two files. In order to connect to the remote system, it has to use the private key. So one should inform that this DIR_PATH/keypairforssh is the private key.

ssh-add DIR_PATH/keypairforssh

Connect to remote host via SSH

If the private key and public key are in the right places, then you can connect to the system in this way.

Читайте также:  Командная строка linux справка

Where username should be a valid user on the remote system and hostname is DNS-recognizable or an IP address so that ssh can contact the remote system and request for connection.

For example, to connect to the system named “linuxhandbook” with the username “seeni” , use:

As explained before, the above command uses the private key on the local system and public key on the remote system and verifies these are valid pairs. It allows login if and only if key pair is valid and spawns a shell (type depends on the configuration for the user on the remote system) for your use. You can use the remote system as you are using the local system.

Suppose the private key is not added to the key agent, then you can do ssh login as below.

This checking of key pairs is usually done once. Ssh adds the remote host to the list of authorized hosts for future usage.

Copying files between client and remote systems

The scp command is a tool built on the top of ssh. It allows users to copy files and directories from remote to client and vice versa.

Since scp command uses ssh, it needs the same requirement as ssh. It means that the public key should be on the remote system and the private key should be on the local system.

scp DIR_PATH_1 DIR_PATH_2

Where DIR_PATH_1/DIR_PATH_2 are both paths that are either remote or local filesystem paths. For example, To transfer ~/Documents/documentForLinux.txt to ‘linuxHandbook‘s /home/seeni/Documents directory

To copy the same file in reverse direction,

scp [email protected]:~/Documents/documentForLinux.txt ~/Documents

Mounting remote filesystem or directory

To mount remote system directories to the client, sshfs is the tool
developed for this specific purpose.

sshfs [email protected]er:/path/to/remote/folder /path/to/local/mount/point

The above command is totally intuitive. Here, ‘name’ is the username accepted on remote system and server is the remote ‘hostname’.

In some systems, sshfs may not be available, install it if you need it.

Tip: The nohup command allows you to keep on running commands even after you disconnect your SSH connection.

Congratulations, you did make it to the end. I hope this article covered all the basic commands and tools related to ssh. These tools are just enough to get started with remote computing with ssh.

In a related article, you can learn about tmate. It’s a tool that allows you to share your terminal session over SSH.

Hope, you find this article useful. If you have any suggestions, feel free to drop them in the comment section below.

Источник

SSH Command — Usage, Options, Configuration

Request demo

This page is about the OpenSSH ssh command on Unix/Linux or the Mac terminal. For general information about SSH and other implementations, see the SSH protocol home page .

Practically every Unix and Linux system includes the ssh command. This command is used to start the SSH client program that enables secure connection to the SSH server on a remote machine. The ssh command is used from logging into the remote machine, transferring files between the two machines, and for executing commands on the remote machine.

Читайте также:  Devices that use linux

Contents

quantum-safe secure file transfer, quantum-safe tunneling, quantum-safe secure remote access

SSH Command in Linux

The ssh command provides a secure encrypted connection between two hosts over an insecure network. This connection can also be used for terminal access, file transfers, and for tunneling other applications. Graphical X11 applications can also be run securely over SSH from a remote location.

Other SSH Commands

There are other SSH commands besides the client ssh . Each has its own page.

  • ssh-keygen — creates a key pair for public key authentication
  • ssh-copy-id — configures a public key as authorized on a server
  • ssh-agent — agent to hold private key for single sign-on
  • ssh-add — tool to add a key to the agent
  • scp — file transfer client with RCP-like command interface
  • sftp — file transfer client with FTP-like command interface
  • sshd — OpenSSH server

Using the Linux client

Linux typically uses the OpenSSH client. The ssh command to log into a remote machine is very simple. To log in to a remote computer called sample.ssh.com, type the following command at a shell prompt:

If this is the first time you use ssh to connect to this remote machine, you will see a message like:

The authenticity of host 'sample.ssh.com' cannot be established.
DSA key fingerprint is 04:48:30:31:b0:f3:5a:9b:01:9d:b3:a7:38:e2:b1:0c.
Are you sure you want to continue connecting (yes/no)?

Type yes to continue. This will add the server to your list of known hosts ( ~/.ssh/known_hosts ) as seen in the following message:

Warning: Permanently added 'sample.ssh.com' (DSA) to the list of known hosts.

Each server has a host key , and the above question related to verifying and saving the host key, so that next time you connect to the server, it can verify that it actually is the same server.

Once the server connection has been established, the user is authenticated. Typically, it asks for a password. For some servers, you may be required to type in a one-time password generated by a special hardware token.

Once authentication has been accepted, you will be at the shell prompt for the remote machine.

Specifying a different user name

It is also possible to use a different username at the remote machine by entering the command as:

ssh alternative-username@sample.ssh.com

The above can also be expressed with the syntax:

ssh -l alternative-username sample.ssh.com

Executing remote commands on the server

The ssh command is often also used to remotely execute commands on the remote machine without logging in to a shell prompt. The syntax for this is:

For example, to execute the command:

on host sample.ssh.com, type the following command at a shell prompt:

ssh sample.ssh.com ls /tmp/doc

After authenticating to the remote server, the contents of the remote directory will be displayed, and you will return to your local shell prompt. -x Disables X11 forwarding.

SSH client configuration file

The ssh command reads its configuration from the SSH client configuration file ~/.ssh/config . For more information, see the page on SSH client configuration file .

openssh, open-source ssh, openssh support

Configuring public key authentication

To configure passwordless public key authentication , you may want to create an SSH key and set up an authorized_keys file. See the pages on ssh-keygen and ssh-copy-id for more information.

Читайте также:  Посмотреть содержимое флешки linux

Configuring port forwarding

Command-line options can be used to set up port forwarding. Local fowarding means that a local port (at the client computer) is tunneled to an IP address and port from the server. Remote forwarding means that a remote port (at the server computer) is forwarded to a given IP address and port from the client machine. See the page on configuring port forwarding on how to configure them.

OpenSSH also supports forwarding Unix domain sockets and IP packets from a tunnel device to establish a VPN (Virtual Private Network).

SSH command line options

Some of the most important command-line options for the OpenSSH client are:

-1 Use protocol version 1 only.

-2 Use protocol version 2 only.

-4 Use IPv4 addresses only.

-6 Use IPv6 addresses only.

-A Enable forwarding of the authentication agent connection.

-a Disable forwarding of the authentication agent connection.

-C Use data compression

-c cipher_spec Selects the cipher specification for encrypting the session.

-D [bind_address:] port Dynamic application-level port forwarding. This allocates a socket to listen to port on the local side. When a connection is made to this port, the connection is forwarded over the secure channel, and the application protocol is then used to determine where to connect to from the remote machine.

-E log_file Append debug logs to log_file instead of standard error.

-F configfile Specifies a per-user configuration file. The default for the per-user configuration file is ~/.ssh/config.

-g Allows remote hosts to connect to local forwarded ports.

-i identity_file A file from which the identity key (private key) for public key authentication is read.

-J [user@] host [:port] Connect to the target host by first making a ssh connection to the pjump host[(/iam/jump-host) and then establishing a TCP forwarding to the ultimate destination from there.

-l login_name Specifies the user to log in as on the remote machine.

-p port Port to connect to on the remote host.

-q Quiet mode.

-V Display the version number.

-v Verbose mode.

-X Enables X11 forwarding.

A little history

SSH replaced several older commands and protocols in Unix and Linux the 1990s. The include telnet , rlogin , and rsh .

SSH runs at TCP/IP port 22. This is right between ftp and telnet, which are 20 years older. Read the story of how SSH got port 22 .

The following video summarizes how and why SSH was originally developed.

We at SSH secure communications between systems, automated applications, and people. We strive to build future-proof and safe communications for businesses and organizations to grow safely in the digital world.

  • Solutions
    • Zero Trust Suite
    • Quantum-Safe Cryptography (QSC)
    • Secure Business Communications
    • Security Risk Mitigation
    • OT security
    • MSP Security
    • Secure Active Directory
    • Just-in-Time Access
    • Secure vendor access
    • Hybrid cloud security
    • Credentials & Secrets Management
    • IT Audits & Compliance
    • PrivX™ Hybrid PAM
    • UKM Zero Trust™
    • Tectia SSH Client/Server™
    • Tectia™ z/OS
    • SSH Deltagon Suite
    • Deltagon Secure Mail
    • Deltagon Secure Sign
    • NQX™ Quantum-Safe
    • SSH Risk Assessment™
    • Professional Services
    • Support
    • Careers
    • References
    • Downloads
    • Manuals
    • Events & Webinars
    • Blog
    • About us
    • Contact
    • Investors
    • Partners
    • Press

    Stay on top of the latest in cybersecurity

    Be the first to know about SSH’s new solutions, product
    updates, new features, and other SSH news!

    Источник

Оцените статью
Adblock
detector